regex

escaping pipe (“|”) in a regex

好久不见. 提交于 2021-02-04 17:09:48
问题 I have a need to split on words and end marks (punctuation of certain types). Oddly pipe ("|") can count as an end mark. I have code that words on end marks until I try to add the pipe. Adding the pipe makes the strsplit every character. Escaping it causes and error. How can I include the pipe int he regular expression? x <- "I like the dog|." strsplit(x, "[[:space:]]|(?=[.!?*-])", perl=TRUE) #[[1]] #[1] "I" "like" "the" "dog|" "." strsplit(x, "[[:space:]]|(?=[.!?*-\|])", perl=TRUE) #Error: '

Python remove spaces in between braces [duplicate]

孤街醉人 提交于 2021-02-04 16:46:39
问题 This question already has answers here : Regex to remove spaces between '[' and ']' (3 answers) Closed 8 months ago . I am using re but I am not having any luck. I want to know how to remove spaces in between braces. For example I have this string i want to go to the[ super mall ](place) You see the the space in "[ super mall]"? What can turn this string into i want to go to the [super mall](place) I would appreciate any help I can get on this thanks. 回答1: I'm assuming braces are balanced and

Search Json Array

非 Y 不嫁゛ 提交于 2021-02-04 16:13:06
问题 I got a json array like below: [ {"value":"uk-icon-adjust","title":"Adjust","url":"#", "text":""}, {"value":"uk-icon-adn","title":"Adn","url":"#", "text":""}, {"value":"uk-icon-align-center","title":"Align center","url":"#", "text":""}, {"value":"uk-icon-align-justify","title":"Align justify","url":"#", "text":""}, {"value":"uk-icon-align-left","title":"Align left","url":"#", "text":""} ] I want to search this json array for specific titles. But the problem is, that I want to search with a

How do you use a plus symbol with a character class as part of a regular expression?

試著忘記壹切 提交于 2021-02-04 15:58:26
问题 in cygwin, this does not return a match: $ echo "aaab" | grep '^[ab]+$' But this does return a match: $ echo "aaab" | grep '^[ab][ab]*$' aaab Are the two expressions not identical? Is there any way to express "one or more characters of the character class" without typing the character class twice (like in the seconds example)? According to this link the two expressions should be the same, but perhaps Regular-Expressions.info does not cover bash in cygwin. 回答1: grep has multiple "modes" of

How do you use a plus symbol with a character class as part of a regular expression?

a 夏天 提交于 2021-02-04 15:57:48
问题 in cygwin, this does not return a match: $ echo "aaab" | grep '^[ab]+$' But this does return a match: $ echo "aaab" | grep '^[ab][ab]*$' aaab Are the two expressions not identical? Is there any way to express "one or more characters of the character class" without typing the character class twice (like in the seconds example)? According to this link the two expressions should be the same, but perhaps Regular-Expressions.info does not cover bash in cygwin. 回答1: grep has multiple "modes" of

How to check if a string starts and ends with specific strings?

Deadly 提交于 2021-02-04 15:54:04
问题 I have a string like: string str = "https://abce/MyTest"; I want to check if the particular string starts with https:// and ends with /MyTest . How can I acheive that? 回答1: This regular expression: ^https://.*/MyTest$ will do what you ask. ^ matches the beginning of the string. https:// will match exactly that. .* will match any number of characters (the * part) of any kind (the . part). If you want to make sure there is at least one character in the middle, use .+ instead. /MyTest matches

How to check if a string starts and ends with specific strings?

让人想犯罪 __ 提交于 2021-02-04 15:52:25
问题 I have a string like: string str = "https://abce/MyTest"; I want to check if the particular string starts with https:// and ends with /MyTest . How can I acheive that? 回答1: This regular expression: ^https://.*/MyTest$ will do what you ask. ^ matches the beginning of the string. https:// will match exactly that. .* will match any number of characters (the * part) of any kind (the . part). If you want to make sure there is at least one character in the middle, use .+ instead. /MyTest matches

Whole word matching with dot characters in MySQL

落爺英雄遲暮 提交于 2021-02-04 15:49:17
问题 In MySQL, when searching for a keyword in a text field where only "whole word match" is desired, one could use REGEXP and the [[:<:]] and [[:>:]] word-boundary markers: SELECT name FROM tbl_name WHERE name REGEXP "[[:<:]]word[[:>:]]" For example, when we want to find all text fields containing "europe", using SELECT name FROM tbl_name WHERE name REGEXP "[[:<:]]europe[[:>:]]" would return "europe map", but not "european union". However, when the target matching words contains "dot characters",

PHP Regex Word Boundary exclude underscore _

白昼怎懂夜的黑 提交于 2021-02-04 15:45:36
问题 I'm using regex word boundary \b, and I'm trying to match foo in the following $sentence but the result is not what I need, the underscore is killing me, I want underscore to be word boundary just like hyphen or space: $sentence = "foo_foo_foo foo-foo_foo"; X X X YES X X Expected: $sentence = "foo_foo_foo foo-foo_foo"; YES YES YES YES YES YES My code: preg_match("/\bfoo\b/i", $sentence); 回答1: You would have to create DIY boundaries. (?:\b|_\K)foo(?=\b|_) 回答2: Does this do what you want?: preg

Pandas Dataframe check if a value exists using regex

China☆狼群 提交于 2021-02-04 15:28:27
问题 I have a big dataframe and I want to check if any cell contains admin string. col1 col2 ... coln 0 323 roster_admin ... rota_user 1 542 assignment_rule_admin ... application_admin 2 123 contact_user ... configuration_manager 3 235 admin_incident ... incident_user ... ... ... ... ... I tried to use df.isin(['*admin*']).any() but it seems like isin doesn't support regex. How can I search though all columns using regex? I have avoided using loops because the dataframe contains over 10 million