regex

Replacing any content inbetween second and third underscore

不羁岁月 提交于 2021-01-27 20:55:48
问题 I have a PowerShell Scriptline that replaces(deletes) characters between the second and third underscore with an "_": get-childitem *.pdf | rename-item -newname { $_.name -replace '_\p{L}+, \p{L}+_', "_"} Examples: 12345_00001_LastName, FirstName_09_2018_Text_MoreText.pdf 12345_00002_LastName, FirstName-SecondName_09_2018_Text_MoreText.pdf 12345_00003_LastName, FirstName SecondName_09_2018_Text_MoreText.pdf This _\p{L}+, \p{L}+_ regex only works for the first example. To replace everything

Contains the word but not a specific word before it

非 Y 不嫁゛ 提交于 2021-01-27 20:38:23
问题 I need help in regular expressions. The code is in SQL and I would like to match the all string that is not referencing proxy database. The pattern would be: Contains .. and the word before it is not equal to proxy I would like to match the example word customer below: from proxy..vw_xxx a join customer..vw_xxx b from proxy..vw_xxx insert into proxy..vw_xxx from customer..vw_xxx Edit: How about if I would also like to capture the DDL statement. For Example: CREATE VIEW vw_yyy AS ... from

Regex: Match everything in text paragraph except specific phrases

烂漫一生 提交于 2021-01-27 20:05:02
问题 I'm writing a free plugin for Google Docs and processing paragraphs of text. I need a regular expression to match everything except a phrase (i.e. multiple words separated with spaces). For example, when searching the text The quick brown fox jumped over the lazy dog I want to match everything except quick brown and lazy with the expected result being The fox jumped over the dog . \b((?!(lazy)\b).)+ This works; it matches all text except lazy and I get The quick brown fox jumped over the dog

Split on spaces not inside parentheses in Python

这一生的挚爱 提交于 2021-01-27 19:54:19
问题 I have a several strings that I want to split by spaces when not inside parentheses. For example sentence = "blah (blah2 (blah3))|blah4 blah5" should produce ["blah", "(blah2 (blah3))|blah4", "blah5"] I've tried: re.split(r"\s+(?=[^()]*(?:\(|$))", sentence) but it produces: ['blah', '(blah2', '(blah3))|blah4', 'blah5'] 回答1: As said in the comments, it's impossible to process that using regex because of parenthesis nesting. An alternative would be some good old string processing with nesting

Regex that match everything except the list of strings

萝らか妹 提交于 2021-01-27 19:33:10
问题 I need regex that match Scheme identifier that will terminate if it find any of the not allowed strings. I have code like this: function make_tokens_re() { var tokens = specials.names() .sort((a, b) => b.length - a.length || a.localeCompare(b)) .map(escape_regex).join('|'); return new RegExp(`(#\\\\(?:x[0-9a-f]+|${character_symbols}|[\\s\\S])|#f|#t|#;|(?:${num_stre})(?=$|[\\n\\s()[\\]])|\\[|\\]|\\(|\\)|\\|[^|]+\\||;.*|(?:#[ei])?${float_stre}(?=$|[\\n\\s()[\\]])|\\n|\\.{2,}|(?!#:|'#[ft])(?:$

regex split into groups

倖福魔咒の 提交于 2021-01-27 19:20:21
问题 My regex-fu is weak today. I'm trying to capture groups in a string into 5 parts with the format: substring delimiter substring number(space) substring I've tried using word boundaries but no success. I've resorted to using *.(greedy and lazy, I know) which is bit better than not working at all Here's what I have: import re s = "FOREVER - Alabaster Cuttlefish - 01 This Style Is Cheese" m = re.compile("(.*)(\s-\s)(\d{1,3}\s)(.*)") g = m.match(s) if g: print m.match(s).group(1) # FOREVER print

RegExp special characters escape

℡╲_俬逩灬. 提交于 2021-01-27 19:20:20
问题 I have messed around with special characters in regular expression for several hours now, and must admit that i give up. Trying to make a password test function, that test for at least one of the following: lowercase, uppercase, integer and special character. The special characters are "¤@+-£$!%*#?&().:;,_". I have used this function to escape them: //used to escape special characters [¤@+-£$!%*#?&().:;,_] RegExp.escape = function(str) { return String(str).replace(/([.*+?^=!:${}()|\[\]\/\\])

Extract embedded number from string - JavaScript Regex

倾然丶 夕夏残阳落幕 提交于 2021-01-27 19:18:59
问题 This deals with the general problem of extracting a signed number from a string that also contains hyphens. Can someone please come up with the regex for the following: "item205" => 205 "item-25 => -25 "item-name-25" => -25 Basically, we want to extract the number to the end of the string, including the sign, while ignoring hyphens elsewhere. The following works for the first two but returns "-name-25" for the last: var sampleString = "item-name-25"; sampleString.replace(/^(\d*)[^\-^0-9]*/, "

regex: how to replace all occurrences of a string within another string, if the original string matches some filter

寵の児 提交于 2021-01-27 19:12:15
问题 i need to replace all occurrences of a string within another string, if the original string matches some filter i can only use a single regex using an s command, because i need to send the assembled command to a 3rd party API i have tried to use positive lookahead as to not consume the string in which i want to replace characters, but somehow i can not get the replacing to work as expected. here is what i have tried so far and what was the outcome: (note that the filter - here [0-9]+ is just

Extract year from a string using PHP regex

陌路散爱 提交于 2021-01-27 19:02:23
问题 I want to extract year from a string. I got an incomplete solution. My string will be always like: Please message mpg of jazz 2014 and 2015+ to my mobile number +123456789 I have tried the following regex; preg_match_all('!\d{4}+| \d{4}+\W!', $str, $matches); This will output the following array. Array ( [0] => Array ( [0] => 2015 [1] => 2014+ [2] => 1234 [3] => 5678 ) ) I need to get only the year portion with + symbol if any. I.e, i want only this: Array ( [0] => Array ( [0] => 2015 [1] =>