regex

regular express : how to exclude multiple character groups?

柔情痞子 提交于 2021-02-06 10:11:26
问题 I have a set of urls : /products /categories /customers Now say a customers is named john, and I want to help john to reach his own account page with a shorter url: before : /customers/john after : /john (suppose customer names are unique) I'm trying to figure out a proper regex dispatcher so all customers can have this feature : /marry /james /tony-the-red-beard here is what I got now(in PHP) : '/^\/([^(products|categories|admin)].+)$/' => /customers/$1 This doesn't seem to work. Anybody can

Is there a way to check if a string in JS is one single emoji?

倖福魔咒の 提交于 2021-02-06 09:48:27
问题 The question is simple: I have a string str , how do I check if str is one single emoji, and nothing else? Additionally I would prefer not using another library. Match "🍎" , "⛹🏿‍♂️" , "3️⃣" but not "🍓a" , "𝕒" , "🍌🍀" I'm having trouble finding a solution but here are some things I've tried so far: Attempted Solution 1 - Play around lengths and ... operator I learned that emojis occupy more than one byte, some even occupy 4 bytes, or more... and we can measure that via the string's length

laravel regex validation not working

核能气质少年 提交于 2021-02-06 09:14:40
问题 I've just started using laravel and I'm working on validating a textarea in one of my forms. The textarea is for the users bio and so I only want to allow letters, numbers, spaces and the following characters: , . ? ; : ' " - () ! / @ $ This is what I have $validator = Validator::make(Input::all(), array('bio' => array('regex:[a-zA-Z0-9 ,\.\?;:\'"-\(\)!/@\$]') ) ); I've been searching and trying a lot to get it to work but I just can't figure it out. Any help would be much appreciated. Thanks

laravel regex validation not working

拈花ヽ惹草 提交于 2021-02-06 09:06:11
问题 I've just started using laravel and I'm working on validating a textarea in one of my forms. The textarea is for the users bio and so I only want to allow letters, numbers, spaces and the following characters: , . ? ; : ' " - () ! / @ $ This is what I have $validator = Validator::make(Input::all(), array('bio' => array('regex:[a-zA-Z0-9 ,\.\?;:\'"-\(\)!/@\$]') ) ); I've been searching and trying a lot to get it to work but I just can't figure it out. Any help would be much appreciated. Thanks

How to validate password using express-validator npm

做~自己de王妃 提交于 2021-02-06 08:50:48
问题 I am writing rest API using node , express web module. For validation I am using express-validator npm. I want to apply some validation rules on password field. How can I achieve it using express-validator? What validation rules I want to apply for password as: min 8 char long. At least one uppercase. At least one lower case. At least one special character. I read in this link that there is a function available called regex() . So I tried it but not working at all. My approach: req.check(

ruby, using regex to find something in between two strings

亡梦爱人 提交于 2021-02-06 01:56:05
问题 Using Ruby + regex, given: starting-middle+31313131313@mysite.com I want to obtain just: 31313131313 ie, what is between starting-middle+ and mysite.com Here's what I have so far: to = 'starting-middle+31313131313@mysite.com' to.split(/\+/@mysite.com.*/).first.strip 回答1: Between 1st + and 1st @ : to[/\+(.*?)@/,1] Between 1st + and last @ : to[/\+(.*)@/,1] Between last + and last @ : to[/.*\+(.*)@/,1] Between last + and 1st @ : to[/.*\+(.*?)@/,1] 回答2: Here is a solution without regex (much

How to find spans with a specific class containing specific text using beautiful soup and re?

我的梦境 提交于 2021-02-05 18:50:13
问题 how can I find all span's with a class of 'blue' that contain text in the format: 04/18/13 7:29pm which could therefore be: 04/18/13 7:29pm or: Posted on 04/18/13 7:29pm in terms of constructing the logic to do this, this is what i have got so far: new_content = original_content.find_all('span', {'class' : 'blue'}) # using beautiful soup's find_all pattern = re.compile('<span class=\"blue\">[data in the format 04/18/13 7:29pm]</span>') # using re for _ in new_content: result = re.findall

include dot(.) and hyphen(-) in a regex

被刻印的时光 ゝ 提交于 2021-02-05 12:30:53
问题 if(preg_match('/[^a-z\-0-9]/i', $value)) { echo "<META HTTP-EQUIV='Refresh' Content='0; URL=http://$ponka/name/error'>"; } how to include a dot and hyphen in the above code? I know how to add dot or hyphen in the code which is if-yes-then-if-then-else. This code is if-no-then-if-then-else (if you got what I am trying to say) 回答1: The hyphen doesn't need to be escaped if it's the first or last in the character class. The dot also doesn't need to escaped when used inside a character class [] i

Sed \w character class not working with replace on mac

拟墨画扇 提交于 2021-02-05 12:28:46
问题 When I execute this command on OSX, I would expect each letter to be replaced by an "x", but none of the letters are replaced: $ echo 'a b c' | sed 's/\w/x/g' output: a b c This works just fine: echo 'a b c' | sed 's/[[:alpha:]]/x/g' output: x x x What am I missing? 回答1: Please note that the BSD implementation of sed on Mac is different from other linux machines You can install gnu sed. Run the following command on Apple Mac OS: $ brew install gnu-sed reference: https://www.cyberciti.biz/faq

Matching an apostrophe only within a word or string

依然范特西╮ 提交于 2021-02-05 12:28:37
问题 I'm looking for a Python regex that can match 'didn't' and returns only the character that is immediately preceded by an apostrophe, like 't , but not the 'd or t' at the beginning and end. I have tried (?=.*\w)^(\w|')+$ but it only matches the apostrophe at the beginning. Some more examples: 'I'm' should only match 'm and not 'I 'Erick's' should only return 's and not 'E The text will always start and end with an apostrophe and can include apostrophes within the text. 回答1: To match an