regex

How do I use regular expressions in PostgreSQL to remove the end of a field matching pattern?

China☆狼群 提交于 2021-01-29 04:57:14
问题 How can I simplify this PostgreSQL? Basically I want to check if the fields end with (1) or just (1) and replace and repeat from numbers from 1-30. I assume it can be done with regular expressions somehow, but I haven't got it working. UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,' (1)')) WHERE name LIKE '% (1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,'(1)')) WHERE name LIKE '%(1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,

Mysql - Capitalize first letter of multiple words of a column without CAP_FIRST

妖精的绣舞 提交于 2021-01-29 04:56:44
问题 I have a table such as the below Name firstname lastname FirstName Lastname firstName Lastname FirstName lastname I am trying to capitalize each letter of the firstname and lastname to be Firstname Lastname in all the 4 cases. Any recommendations on the query without using the CAP_FIRST function? Can I use regex? 回答1: This is a query that works: SELECT CONCAT( UPPER(SUBSTRING(Name,1,1)), LOWER(SUBSTRING(Name,2,Locate(' ', Name)-1)), UPPER(SUBSTRING(Name,Locate(' ', Name)+1,1)), LOWER

Parsing text using grep

别来无恙 提交于 2021-01-29 04:55:27
问题 I have a textfile called netlist.txt with the following contents: M1 nmos1 M2 nmos2 P1 pmos1 M3 nmos3 M4 nmos4 P2 pmos2 I want to retrieve only the line which starts with a tab/space and matching all the "M" values that are indented, using regex. In order to accomplish this I entered the following expression in bash: egrep [:space:]*[M][0-9]+ netlist.txt But it doesn't recognize the space. It retrieves all the lines regardless of having a space or not. Please give me some advice on this.

Key error when using regex quantifier python

假装没事ソ 提交于 2021-01-29 04:53:06
问题 I am trying to capture words following specified stocks in a pandas df. I have several stocks in the format $IBM and am setting a python regex pattern to search each tweet for 3-5 words following the stock if found. My df called stock_news looks as such: Word Count 0 $IBM 10 1 $GOOGL 8 etc pattern = '' for word in stock_news.Word: pattern += '{} (\w+\s*\S*){3,5}|'.format(re.escape(word)) However my understanding is that {} should be a quantifier, in my case matching between 3 to 5 times

How do I use regular expressions in PostgreSQL to remove the end of a field matching pattern?

给你一囗甜甜゛ 提交于 2021-01-29 04:52:21
问题 How can I simplify this PostgreSQL? Basically I want to check if the fields end with (1) or just (1) and replace and repeat from numbers from 1-30. I assume it can be done with regular expressions somehow, but I haven't got it working. UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,' (1)')) WHERE name LIKE '% (1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,'(1)')) WHERE name LIKE '%(1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,

Key error when using regex quantifier python

心已入冬 提交于 2021-01-29 04:41:38
问题 I am trying to capture words following specified stocks in a pandas df. I have several stocks in the format $IBM and am setting a python regex pattern to search each tweet for 3-5 words following the stock if found. My df called stock_news looks as such: Word Count 0 $IBM 10 1 $GOOGL 8 etc pattern = '' for word in stock_news.Word: pattern += '{} (\w+\s*\S*){3,5}|'.format(re.escape(word)) However my understanding is that {} should be a quantifier, in my case matching between 3 to 5 times

regex error : raise error, v # invalid expression

冷暖自知 提交于 2021-01-29 04:37:31
问题 I have a variable device='A/B/C/X1' that is commented out in another file. There can be multiple instances of the same device such as 'A/B/C/X1@1' , ..@2 and so on. All of these devices are commented out in another file with a prefix * . I want to remove the * but not affect similar devices like 'A/B/C/X**10**' . I tried using regex to simply substitute a pattern using the following line of code, but I'm getting an InvalidExpression error. line=re.sub('^*'+device+'@',device+'@',line) Please

regex error : raise error, v # invalid expression

巧了我就是萌 提交于 2021-01-29 04:36:24
问题 I have a variable device='A/B/C/X1' that is commented out in another file. There can be multiple instances of the same device such as 'A/B/C/X1@1' , ..@2 and so on. All of these devices are commented out in another file with a prefix * . I want to remove the * but not affect similar devices like 'A/B/C/X**10**' . I tried using regex to simply substitute a pattern using the following line of code, but I'm getting an InvalidExpression error. line=re.sub('^*'+device+'@',device+'@',line) Please

Regular Expression Repeating Pattern delimited by comma

*爱你&永不变心* 提交于 2021-01-29 04:31:48
问题 I have a regular expression of the following in Javascript: /\w{1,}\s*\w{1,}/ This checks if a string has atleast two words greater than 1 character each. Ex- asd fgh - Valid a b d dfd - Valid xscxs - Invalid I now have a new requirement that I have tried to implement, but cannot get right. New requirement: Be able to have a comma separated list of the same type of input as before. Cannot end with a comma. Each item must be valid per the rules above. If there are no comma then also its valid.

How to insert an arbitrary string after pattern with sed

只愿长相守 提交于 2021-01-29 04:18:12
问题 It must be really easy, but somehow I don't get it… I want to process an HTML-file via a bash script and insert an HTML-String into a certain node: org.html: <div id="wrapper"></div> MYTEXT=$(phantomjs capture.js www.somesite.com) # MYTEXT will look something like this: # <div id="test" style="top: -1.9%;">Something</div> sed -i "s/\<div id=\"wrapper\"\>/\<div id=\"wrapper\"\>$MYTEXT/" org.html I always get this error: bad flag in substitute command: 'd' which is probably because sed