regex-lookarounds

Regex for Parsing JSON

怎甘沉沦 提交于 2019-12-08 13:30:52
I have a column of data I'm reading in Tableau directly from Redshift. This column contains a JSON object. It looks like this: {"Age": 58, "City": "Wisconsin Rapids", "Race": "Other", "State": "Wisconsin", "Gender": "Female", "Country": "United States"} I wish to extract this data by generating a column with a calculated field for each data point of interest using Tableau's REGEXP_EXTRACT function. I.e. an Age column, a City column etc. How do I write a line of regular expressions to get the value of 58 for Age, Wisoncsin Rapids for City, etc. Thanks! You can use this regex : "Age"\s?+:\s?+"?(

Return the next nth result \w+ after a hyphen globally

牧云@^-^@ 提交于 2019-12-08 09:00:01
问题 Just getting to the next stage of understanding regex, hoping the community can help... string = These.Final.Hours-AUSVERSION.2013-TEST-TESTAGAIN-YIFY.cp(tt123456).MiLLENiUM.mp4 There are multiple test names preceded by a '-' hyphen which I derive from regex \(?<=-)\w+\g Result: AUSVERSION TEST TESTAGAIN YIFY I can parse the very last result using greediness with regex \(?!.*-)(?<=-)\w+\g Result: YIFI (4th & last result) Can you please help me parse either the 1st, 2nd, or 3rd result Globally

Regex removing anything that is not a 14-digit number followed with space

三世轮回 提交于 2019-12-08 04:55:24
I'm trying to invert this expression: ([0-9]{14} ) , so all 14 digit numbers followed by a space. I looked everywhere, and it seems that the best way should be using negative lookahead . But when I try apply q(?!u) to my case >> (?!([0-9]{14} )) , it doesn't work. What am I doing wrong? I will appreaciate any advice, thank you. The point is to remove everything that is not a 14-digit chunk of text while preserving those 14-digit chunks. If you want to delete text other than 14 digits followed with a space, use (\b\d{14} )|. and replace with $1 . The pattern matches and captures (we can refer

Regex get text before and after a hyphen

人盡茶涼 提交于 2019-12-08 03:01:25
I have this string: "Common Waxbill - Estrilda astrild" How can I write 2 separate regexes for the words before and after the hyphen? The output I would want is: "Common Waxbill" and "Estrilda astrild" If you cannot use look-behinds, but your string is always in the same format and cannout contain more than the single hyphen, you could use ^[^-]*[^ -] for the first one and \w[^-]*$ for the second one (or [^ -][^-]*$ if the first non-space after the hyphen is not necessarily a word-character. A little bit of explanation: ^[^-]*[^ -] matches the start of the string (anchor ^ ), followed by any

Regex PHP. Reduce steps: limited by fixed width Lookbehind

若如初见. 提交于 2019-12-08 02:38:18
问题 I have a regex that will be used to match @users tags. I use lokarround assertions, letting punctuation and white space characters surround the tags. There is an added complication, there are a type of bbcodes that represent html. I have two types of bbcodes, inline ( ^B bold ^b ) and blocks ( ^C center ^c ). The inline ones have to be passed thru to reach for the previous or next character. And the blocks are allowed to surround a tag, just like punctuation. I made a regex that does work.

RegEx for adding underscore before capitalized letters

瘦欲@ 提交于 2019-12-07 15:32:51
问题 How do I add underscore (_) before capitalized letters in a string, excepted the first one ? [1] "VarLengthMean" "VarWidthMean" I want it to become : [1] "Var_Length_Mean" "Var_Width_Mean" I considered using str_replace_all from stringr , but I can't figure out which regexp I should use. How do I solve this problem? 回答1: One option would be to capture the lower case letter and the following upper case letter, and then insert the _ while adding the backreference ( \\1 , \\2 ) of the captured

Regex match everything between two {}

跟風遠走 提交于 2019-12-07 11:41:48
问题 I was looking at different answers here but unfortunately none of them was good for my case. So I hope you don't mind about it. So I need to match everything between two curly brackets {} except situation when match starts with @ and without these curly brackets e.g: "This is a super text { match_this }" "{ match_this }" "This is another example @{deal_with_it}" Here are my test strings, 1,2,3 are valid while the last one shouldn't be: 1 {eww} 2 r23r23{fetwe} 3 #{d2dded} 4 @{d2dded} I was

Java regex with a positive look behind of a negative look ahead

我只是一个虾纸丫 提交于 2019-12-07 06:29:59
问题 I am trying to extract from this kind of string ou=persons,ou=(.*),dc=company,dc=org the last string immediately preceded by a coma not followed by (.*). In the last case, this should give dc=company,dc=org . Looking on regex, this seems to be a positive look behind (preceded by) of a negative look ahead. So I have achieve this regex: (?<=(,(?!.*\Q(.*)\E))).* , but it returns ,dc=company,dc=org with the coma. I want the same thing without the coma. What I am doing wrong? 回答1: The comma

Return the next nth result \\w+ after a hyphen globally

柔情痞子 提交于 2019-12-06 14:36:01
Just getting to the next stage of understanding regex, hoping the community can help... string = These.Final.Hours-AUSVERSION.2013-TEST-TESTAGAIN-YIFY.cp(tt123456).MiLLENiUM.mp4 There are multiple test names preceded by a '-' hyphen which I derive from regex \(?<=-)\w+\g Result: AUSVERSION TEST TESTAGAIN YIFY I can parse the very last result using greediness with regex \(?!.*-)(?<=-)\w+\g Result: YIFI (4th & last result) Can you please help me parse either the 1st, 2nd, or 3rd result Globally using the same string? In Python, you can get these matches with a simple -\s*(\w+) regex and re

RegEx find all XML tags

坚强是说给别人听的谎言 提交于 2019-12-06 08:17:15
How do I match all the beginning tags in an XML document with RegEx? I just need to collect the tag names used. This is what I have: (?<=<)(.*?)((?= \/>)|(?=>)) this matches all the beginning and closing tags. Example: <Habazutty>yaddayadda</Habazutty> <Vogons /> <Targ>blahblah</Targ> Above code matches: Habazutty /Habazutty Vogons Targ /Targ I only need Habazutty Vogons Targ I couldn't figure out a way to exclude the closing tags. Negative lookahead didn't work - found nothing. I must have messed up. You could change (?<=<)(.*?)((?= \/>)|(?=>)) to (?<=<)([^\/]*?)((?= \/>)|(?=>)) , i.e.