regex

Grails/Groovy regular expression- how to use (?i) to make everything case insensitive?

那年仲夏 提交于 2021-01-02 05:12:26
问题 I use the following RegEx: url (blank:false, matches: /^(https?:\/\/)(?:[A-Za-z0-9]+([\-\.][A-Za-z0-9]+)*\.)+[A-Za-z]{2,40}(:[1-9][0-9]{0,4})?(\/\S*)?/) I want to add (?i) to make everything case insensitive. How should I add this? 回答1: I can confirm the (?i) at the beginning of the regex makes it case insensitive. Anyway, if your purpose is to reduce the regex length you can use the groovy dollar slashy string form. It allows you to not escape slashes / (the escape char becomes $ ). In

Raku regex: Inconsistent longest token matching

若如初见. 提交于 2021-01-02 05:02:34
问题 Raku's regexes are expected to match longest token. And in fact, this behaviour is seen in this code: raku -e "'AA' ~~ m/A {say 1}|AA {say 2}/" # 2 However, when the text is in a variable, it does not seem to work in the same way: raku -e "my $a = 'A'; my $b = 'AA'; 'AA' ~~ m/$a {say 1}|$b {say 2}/" # 1 Why they work in a different way? Is there a way to use variables and still match the longest token? 回答1: There are two things at work here. The first is the meaning of "longest token". When

RegEx for maximum length in JavaScript

时光怂恿深爱的人放手 提交于 2021-01-02 04:51:29
问题 How can I limit the length of a string matching a RegEx I assumed that var sixCharsRegEx = /^.{6,7}/ would only match strings of lengths 6 or 7 but no: http://jsfiddle.net/FEXbB/ What am I missing? 回答1: You are missing closing dollar at the end. Correct one is: /^.{6,7}$/ 回答2: Match the start and the end. var sixCharsRegEx = /^.{6,7}$/; Your improved example 回答3: you must use end of string symbol $ like this ^.{6,7}$ 回答4: You are missing the end anchor: var sixCharsRegEx = /^.{6,7}$/ 来源:

Selecting a string and ignoring spaces

核能气质少年 提交于 2021-01-02 03:51:10
问题 Does anyone know how to select the text " Some words & things (lp4) " below? I am trying to select [ something ] that is between two spaces \s and that has one or more + words \b in the selection var string = ' \n Some words & things (lp4) '; var regexp = /\s[\b*]\s/i; var selection = string.match(regexp); console.log(selection); 回答1: It is not exactly clear to me what you are trying to achieve. So I will cover two possibilities. 1st case: remove whitespaces If all you basically want is to

Selecting a string and ignoring spaces

橙三吉。 提交于 2021-01-02 03:51:02
问题 Does anyone know how to select the text " Some words & things (lp4) " below? I am trying to select [ something ] that is between two spaces \s and that has one or more + words \b in the selection var string = ' \n Some words & things (lp4) '; var regexp = /\s[\b*]\s/i; var selection = string.match(regexp); console.log(selection); 回答1: It is not exactly clear to me what you are trying to achieve. So I will cover two possibilities. 1st case: remove whitespaces If all you basically want is to

Multiple stems on makefile target

爷,独闯天下 提交于 2021-01-01 09:22:50
问题 Assume ls produces a b c d and I want to create files a-b b-d c-b , etc. To make a-b , I'd use a command such as cat a b > a-b , and similarly for the other ones. I wanted to use a makefile , but couldn't figure out how. I needed something such as: FILES := a-b b-d c-b $(FILES): %1-%2: %1 %2 cat $^ > $@ Here %1 and %2 would be something like \1 and \2 in some regex notations. Is there any simple way to do this? I found this answer, but it seemed to me too complicated and ugly for such a

Regex which matches URN by rfc8141

放肆的年华 提交于 2021-01-01 09:19:21
问题 I am struggling to find a Regex which could match a URN as described in rfc8141. I have tried this one: \A(?i:urn:(?!urn:)(?<nid>[a-z0-9][a-z0-9-]{1,31}):(?<nss>(?:[a-z0-9()+,-.:=@;$_!*']|%[0-9a-f]{2})+))\z but this one only matches the first part of the URN without the components. For example lets say we have the corresponding URN: urn:example:a123,0%7C00~&z456/789?+abc?=xyz#12/3 We should match the following groups: NID - example NSS - a123,0%7C00~&z456/789 (from the last ':' tll we match '

Java regex to check if string is valid number format (comma and decimal point placing)

霸气de小男生 提交于 2021-01-01 08:57:10
问题 1000 - valid 1,000 - valid 1,000.00 - valid 1000.00 - valid 1000.00.00 - invalid 1,0.00 - invalid 1,000,00.00 - invalid 1,000,000.12 - valid no of decimal places can be unlimited I've been trying to find the right regex pattern, can't seem to find one that will accomodate all validations. Can anyone help the pattern ^[1-9]\d{0,2}(.\d{3})*(,\d+)?$ did not work for me, based from the similar thread here 回答1: You should try this expression: ^\d{1,3}|\d(([ ,]?\d{3})*([.,]\d{2}+)?$) With this

Java regex to check if string is valid number format (comma and decimal point placing)

五迷三道 提交于 2021-01-01 08:56:14
问题 1000 - valid 1,000 - valid 1,000.00 - valid 1000.00 - valid 1000.00.00 - invalid 1,0.00 - invalid 1,000,00.00 - invalid 1,000,000.12 - valid no of decimal places can be unlimited I've been trying to find the right regex pattern, can't seem to find one that will accomodate all validations. Can anyone help the pattern ^[1-9]\d{0,2}(.\d{3})*(,\d+)?$ did not work for me, based from the similar thread here 回答1: You should try this expression: ^\d{1,3}|\d(([ ,]?\d{3})*([.,]\d{2}+)?$) With this

Find if the sentence does not contains specific words

谁说胖子不能爱 提交于 2021-01-01 08:12:17
问题 i have a regular expression which find if the sentence s contains specific words my query is: (?=.*hello)(?=.*hi)(?=.*hey).* but now i want to check if my sentence does not contains this words i have tried: (?=.*((?!hello).))(?=.*((?!hi).))(?=.*((?!hey).)).* but it does not works how should i build my query? Example: this query should return true when my sentence is: hi, how are you? and must return false when my sentence is: hi hello hey .. thanks in advance, 回答1: If the problem is to match