regex

Using regex to extract an image url from string

爷,独闯天下 提交于 2021-01-29 02:53:23
问题 I have a string that looks like this: var complicatedString = "<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/32.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Sunny\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Fri - Sunny. High: 23Low: 13\n<BR /> Sat - Thunderstorms. High: 25Low: 15\n<BR /> Sun - Thunderstorms. High: 28Low: 21\n<BR /> Mon - Partly Cloudy. High: 24Low: 17\n<BR /> Tue - Partly Cloudy. High: 26Low: 18\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather

RegEx to allow letters numbers and spaces but not two spaces in a row

孤者浪人 提交于 2021-01-29 02:52:16
问题 Hello I have a RegEx that allows up to 18 characters with numbers, letters and spaces only. How can I modify this to check if the string is starting with a space, or has two spaces in a row? /^[0-9A-Za-z\s]{1,18}$/ I am using this regex in both native javascript (not jquery) and PHP. 回答1: You can use a negative look-ahead to check if the string starts with a space or has 2 or more consecutive spaces, something like: ^(?!.*\s{2,})(?!^ )[0-9A-Za-z\s]{1,18}$ 回答2: (?:(?![ ]{2}).)+ use this regex.

Singular and Plural words matching with Pandas

佐手、 提交于 2021-01-29 02:37:22
问题 This question is an extension to my previous question Multiple Phrases Matching Python Pandas. Although I had figured out the way after an answer to solve my problem, some typical problem in singular and plural words appeared. ingredients=pd.Series(["vanilla extract","walnut","oat","egg","almond","strawberry"]) df=pd.DataFrame(["1 teaspoons vanilla extract","2 eggs","3 cups chopped walnuts","4 cups rolled oats","1 (10.75 ounce) can Campbell's Condensed Cream of Chicken with Herbs Soup","6

Regex to match any character repeated three or more times in R

时光总嘲笑我的痴心妄想 提交于 2021-01-29 02:28:58
问题 What is the Regex to match any character repeated three or more times in R (e.g. "aaargh", "arrrrrgh", "yesssssss")? I read the solution for Python, PHP and PCRE on Stack Overflow, but they don't seem to be applicable to R. Thanks. 回答1: We can use grep grep("(.)\\1{2,}", v1) data v1 <- c("aaargh", "arrrrrgh", "yesssssss") 来源: https://stackoverflow.com/questions/38263441/regex-to-match-any-character-repeated-three-or-more-times-in-r

How to make html link with php regex

走远了吗. 提交于 2021-01-29 02:28:21
问题 My string [[https://example.com|link]] to convert <a href="https://example.com>link</a> My regex is /\[{2}(.*?)\|(.*?)\]{2}/s But it's not working.I am new to php regex. 回答1: You may use preg_replace('~\[\[((?:(?!\[\[).)*?)\|(.*?)]]~s', '<a href="$1">$2</a>', $string) See the regex demo Details \[\[ - a [[ substring ((?:(?!\[\[).)*?) - Group 1 ( $1 in the replacement pattern refers to the value inside this group): any char ( . ), 0 or more occurrences but as few as possible ( *? ), that does

Regular Expression Match And Compare Captured Groups

旧时模样 提交于 2021-01-29 02:27:21
问题 I'm trying to match some strings of the pattern: event = sometext1 name = prefix sometext2 I want to match all cases that sometext1 and sometext2 are different. How should I do it with regular expression? Thanks! 回答1: You can use this regex: event += +(\w+) +name+ = +\w+ +((?!\1)\w+)\b RegEx Demo 回答2: Use a backreference like this: ^event = ([^\s]+) name = prefix (?!\1).+$ Debuggex Demo 来源: https://stackoverflow.com/questions/28889304/regular-expression-match-and-compare-captured-groups

C regular expressions, regcomp

旧城冷巷雨未停 提交于 2021-01-29 02:25:36
问题 I'm trying to make my way around with regular expressions an check if a String is an integer. I figured the pattern should be ^\d$ and I wrote a function to print an error if the argument is not fit: regex_t regex; void check_int(char *c) { check=regcomp(&regex,"^\d$",0); if (check!=0) { perror("4th element on the line is not an integer!"); exit(5); } else printf("4th arg is a number."); } I'm not sure how regcomp works, I used it as I thought I should after checking some examples on the

How to make html link with php regex

若如初见. 提交于 2021-01-29 02:22:30
问题 My string [[https://example.com|link]] to convert <a href="https://example.com>link</a> My regex is /\[{2}(.*?)\|(.*?)\]{2}/s But it's not working.I am new to php regex. 回答1: You may use preg_replace('~\[\[((?:(?!\[\[).)*?)\|(.*?)]]~s', '<a href="$1">$2</a>', $string) See the regex demo Details \[\[ - a [[ substring ((?:(?!\[\[).)*?) - Group 1 ( $1 in the replacement pattern refers to the value inside this group): any char ( . ), 0 or more occurrences but as few as possible ( *? ), that does

Replacing patterns in a string

半城伤御伤魂 提交于 2021-01-29 02:10:19
问题 I have several strings in this format. The separator is a dash ( - ) and each "thing" in between is a marker. string <- "FA-I2-I2-I2-EX-I2-I3-FA-I1-I2-TR-I1-I2-FA-I3-I1-FAFANR-I3-I2-TR-I1-I2-I1-I2-FA-I2-I1-I3-FAQU-I1-I2-I2-I2-NR-I2-I2-NR-I1-I2-I1-NR-I3-QU-I2-I3-QUNR-I2-I1-NRQUQU-I2-I1-EX" I want to identify cases wherever markers containing the letter "I" occurs in a row (i.e. the markers I1, I2, and I3). Then I want to replace those with a description that has no separators. For example, the

Convert a multi-line string into a javascript object

坚强是说给别人听的谎言 提交于 2021-01-29 01:50:20
问题 I've my raw data that looks like this: Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID Last Name, First Name (Details-Details) #ID x1000 I'd like to convert into a loopable object with keys and values something like: var d = { "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName LastName": "#ID"; "FirstName