Using regex File Search, how to search across new lines? - eclipse

I would like my File Search to find occurrences of insert name, regardless of interceding characters or new lines. I would like to find both:
insert into name
insert into
name
insert.*name - works for the first occurrence but not the second
(?s)insert.*name - fails to find either line
insert((.|\n)*)name - gives an error

Use [\s\S] instead of .:
insert[\s\S]*name
or not greedy (if in insert name - insert name there should be two matches instead of one match of the whole sentence):
insert[\s\S]*?name

Related

How to replace value in URL in postgresql

I am trying to replace 5e0361f5af70f400441148 in https://place.mycompany.com/analyst/5e0361f5af70f40044112148/dbt to id. In the end should receive
https://place.mycompany.com/analyst/id/dbt
I use regexp_replace('https://place.mycompany.com/analyst/5e0361f5af70f400441148/dbt','[[:digit:]]','','g') but i do not know how to replace alphabet also
If that Id is always using lowercase a-f, the following will do:
SELECT regexp_replace('https://place.mycompany.com/analyst/5e0361f5af70f400441148/dbt' , '/[0-9,a-f]+/','/id/');
Otherwise add the A-F range: '/[0-9,a-f,A-F]+/'
This will break if other parts of your url contain [0-9,a-f] characters only.
If your input contains more than one id, add a 'g' modifier like so:
SELECT regexp_replace('https://place.mycompany.com/analyst/5e0361f5af70f40044112148/dbt/5e036445af70f40b1012b48f/top-chart', '/[0-9,a-f]+/','/id/','g');

How to replace a string by a subtring in postgres?

I have the following file name in a column on my db: /folder/path/24/24_1543250974365.wav
And I want to replace it by: 24_1543250974365.wav
In summary, I need to cut off the path and replace it by what comes after the last "/" in the String.
My idea is to find the last occurrence of "/" and get the string from there to the end and do a replacement, but not sure if that's the best way to do that
UPDATE tablename
SET file = REPLACE(file, file, substring('/', 1))
WHERE id=1;
I'll need a function that replace all data in this column, so I don't have anymore the entire path but only the file name. Any help would be appreciated!
You might have to add or subtract 1, but this should work
right(file,strpos(reverse(file),'/'))
select right(file,position('/' in reverse(file))-1)

The value in "sym" file disappears when using splayed tables

I am using the following line:
`:c:/dir/ set .Q.en[`:c:/dir; tablename]
Everything is ok if I don't exit KDB, but if I do and then try to load the table using
get `dir
all the symbol columns are integer. I would really appreciate your help into understanding why this happens.
It looks like you forgot to repeat the table name on the l.h.s. of set.
Try
q)`:c:/dir/tablename/ set .Q.en[`:c:/dir; tablename]
This will correctly save table columns in c:/dir/tablename subdirectory and place the sym file alongside. Now you should be able to load both your table and the sym file by using the \l command or specifying c:/dir on the command line when you restart q
q c:/dir
or
q
q)\l c:/dir
(no backticks or leading :'s in either of those commands)
If you want to use get on this table, you will have to load sym separately:
q)load`:c:/dir/sym
q)get`:c:/dir/tablename/
(note the leading : in the path specs)
Finally, you may want to take a look at the rsave command which will save your table without you having to write tablename twice.
.Q.en takes 2 oarams - file handle and table data
Your first param isnt a hsym - should be backtick then colon then path to your db root
Also set takes 2 params - first in this case should be the path to where you want to save like dir/splayedTableName/

Determine if string exists in file

I have a list of strings such as:
John
John Doe
Peter Pan
in a .txt file.
I want to make a loop that checks if a certain name exists. However, I do not want it to be true if I search for "Peter" and only "Peter Pan" exists. Each line has to be a full match.
Ha ha, ep0's answer is very sophisticated!
However, you want to use a parsing loop something like this (this example expects that your names are separated by carriage returns). Consider that you have a text file with contents arranged like this:
John
Harry
Bob
Joe
Here is your script:
fileread, thistext, %whatfile% ;get the text from the file into a variable
;Now, loop through each line and see if it matches your results:
loop, parse, thistext, `r`n, `r`n
{
if(a_loopfield = "John")
msgbox, Hey! It's John!
else
msgbox, No, it's %a_loopfield%
}
If your names are arranged in a different order, you might have to either change the delimiter for the parsing loop, or use regex instead of just a simple comparison.
If you want to check for multiple names use a trie. If you have just one name, you can use KMP.
I'll explain this for multiple names you want to check that exist, since for only one, the example provided on Wikipedia is more than sufficient and you can apply the same idea.
Construct the said trie from your names you want to find, and for each line in file, traverse the trie character by character until you hit a final node.
BONUS: trie is used by Aho-Corasick algorithm, which is an extension of KMP to multiple patters. Read about it. It's very worthwhile.
UPDATE:
For checking if a single name exists, hash the name you want to find, then read the text file line by line. For each line, hash it with the same function and compare it to the one you want to find. If they are equal, compare the strings character by character. You need to do this to avoid false positives (see hash collisions)

Vim - custom syntax - how to match second word

I'm trying to make a custom syntax highlighting for Sybase T-SQL and I'm stuck when I try to match table name in the following line:
UPDATE myTableName
I've tried:
syn match tsqlUpdateTableName "\w\+" contained
syn match tsqlUpdateLine "update.*" nextgroup=tsqlUpdateTableName
hi tsqlUpdateTableName guifg=white guibg=red
But it does not match myTableName
I would appreciate any help.
Cheers!
The problem is that the nextgroup only matches after the current group's match.
You can fix this by excluding the table name in the line match, either by dropping the .* or, as I've done here, by asserting the following table name but ending the match with \ze:
syn match tsqlUpdateTableName "\w\+" contained
syn match tsqlUpdateLine "update \ze\w\+" nextgroup=tsqlUpdateTableName
Alternatively, you can include the table name in the line match and use contains= instead:
syn match tsqlUpdateTableName "update \zs\w\+" contained
syn match tsqlUpdateLine "update \w\+" contains=tsqlUpdateTableName
PS: You should probably tighten your patterns to entire-word matches, e.g. "\<update\>; otherwise, it may mistakenly match inside words like catchupdate.