regex

Redshift regexp_substr

被刻印的时光 ゝ 提交于 2021-02-04 20:55:29
问题 I want to replicate this regex pattern to regexp_substr. I want to capture the second group. '(\?)(.*?)(&|$)' I have tried this regexp(my_url, '\\?.*?&|$') And some similar variations of the above, but I have been getting the errror: ERROR: XX000: Invalid preceding regular expression prior to repetition operator. The error occured while parsing the regular expression: '\?.*?>>>HERE>>>&|$'. 回答1: Since Amazon Redshift supports only POSIX regex, you need to use greedy quantifiers rather than

C# regex for matching sepcific text inside nested parentheses

我的梦境 提交于 2021-02-04 20:52:14
问题 I have these code lines for take to operators between parentheses: string filtered = Regex.Replace(input, "\\(.*?\\)", string.Empty); var result = filtered.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Where(element => element == "OR" || element == "AND"); string temp = string.Join(" ", result); These lines do not work for nested parentheses. For example; it is working for this input : X1 OR ( X2 AND X3 AND X4 AND X5 ) OR X6 It give me this result: OR OR But, when my input has

Regular expression to find number in parentheses, but only at beginning of string

拜拜、爱过 提交于 2021-02-04 20:37:54
问题 Disclaimer: I'm new to writing regular expressions, so the only problem may be my lack of experience. I'm trying to write a regular expression that will find numbers inside of parentheses, and I want both the numbers and the parentheses to be included in the selection. However, I only want it to match if it's at the beginning of a string. So in the text below, I would want it to get (10), but not (2) or (Figure 50). (10) Joystick Switch - Contains control switches (Figure 50) Two (2) heavy

C# remove line using regular expression, including line break

纵饮孤独 提交于 2021-02-04 19:57:16
问题 I need to remove lines that match a particular pattern from some text. One way to do this is to use a regular expression with the begin/end anchors, like so: var re = new Regex("^pattern$", RegexOptions.Multiline); string final = re.Replace(initial, ""); This works fine except that it leaves an empty line instead of removing the entire line (including the line break). To solve this, I added an optional capturing group for the line break, but I want to be sure it includes all of the different

Powershell - How to UpperCase a string found with a Regex [duplicate]

痴心易碎 提交于 2021-02-04 19:50:31
问题 This question already has answers here : Lambda Expression in Powershell (3 answers) Closed last year . I am writing a powershell script to parse the HTM file. I need to find all the links file in the file and then uppercase the filepath, filename and extention. (could be 30 or 40 links in any file). The part I'm having trouble with is the 2nd part of the -replace staement below (the 'XXXX' part). The regex WILL find the strings I'm looking for but I can't figure out how to 'replace' that

Regex - Match up until there's an equal amount of 2 specific characters

廉价感情. 提交于 2021-02-04 19:50:11
问题 For example if I have the following sentence: a cat bit a dog on the butt before running away If the 2 characters I want to use are 'a' and 'b' then I want to match up until the point where there are equal amounts of 'a' and 'b' like the following: a cat bit a dog on the butt b In the above case, the sentence has 5 a's and 3 b's. I want to much up to the point where I have 3 a's and 3 b's. Thank you for the help. 回答1: var a = 0, b = 0; var result = 0; var patten = /./g; for (;patten.exec("a

Powershell - How to UpperCase a string found with a Regex [duplicate]

泪湿孤枕 提交于 2021-02-04 19:50:06
问题 This question already has answers here : Lambda Expression in Powershell (3 answers) Closed last year . I am writing a powershell script to parse the HTM file. I need to find all the links file in the file and then uppercase the filepath, filename and extention. (could be 30 or 40 links in any file). The part I'm having trouble with is the 2nd part of the -replace staement below (the 'XXXX' part). The regex WILL find the strings I'm looking for but I can't figure out how to 'replace' that

Regular expression for parse function arguments with functions

≯℡__Kan透↙ 提交于 2021-02-04 19:47:10
问题 I want to get the function arguments of string. sample( 5*5 ) euros This works correctly with: ([^\s\)]+)\(([^\)]+)\) Demo here. The problem is when I put another function inside the argument: sample( decimal( 5*5 ) ) euros With only a function this works with: ([^\s\)]+)\((.+)\) Demo here. But with two functions or more I can't get the function arguments: sample( decimal( 5*5 ) ) toString(euros) How can I get the function arguments with a regular expression?. 回答1: If you are writing a parser

Regex to pull out the string between 2 underscores

两盒软妹~` 提交于 2021-02-04 19:44:05
问题 I have a pattern of type anystring_OPCtarget_anystring . Can I get some help as how to verify if the string between the 2 underscores is of type "OPC(target)" and pull out the target using regex. Suppose if my string is: MP700000001_OPC32_812345643 first, I need to verify if the string between underscores starts with OPC and then get the target text after OPC and before the 2nd underscore. Help appreciated!!! Thank you 回答1: You can use this regex: ^[^_]*_OPC\K[^_]+ And grab matched data. ^[^_

awk - Variable expansion in regex

瘦欲@ 提交于 2021-02-04 19:39:40
问题 Why doesn't something like this work: echo 4 | awk --assign=abc=4 '/$abc/' The actual example is much more complicated. Basically I have a regex I need repeated several times so I'm storing it in abc . Is there any way to expand an awk variable in /<regex>/ ? I've tried single and double quotes, every combination. I really need that line to be single quoted because I have several double quotes, it actually looks more like awk --assign=test=something '/$test/ { a lot of stuff here inc $test