regex

RegEx for positive number + greater than zero an decimal (0.1)

穿精又带淫゛_ 提交于 2021-01-28 15:39:46
问题 I want to validate a field in javascript to have at least 1 and should be positive number or decimal. Examples: 1 1.1 0.1 10.10 My current regex looks like this: var _RegEx = /^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/; 回答1: Simple: /^\+?(\d*[1-9]\d*\.?|\d*\.\d*[1-9]\d*)$/.test(x) Simpler: 0 < parseInt(x, 10) && parseInt(x, 10) < Infinity Simplest: 0 < +x && +x < Infinity && !/[^\d.+]/.test(x) Thanks to Jack, the last one is not so simple anymore. :/ 回答2: ^((0?0?\.([1-9]\d*|0[1-9]\d*))|(([1-9]|0

How can I get preg_match_all to match angle brackets?

可紊 提交于 2021-01-28 15:37:01
问题 I know it's probably a dumb question, but I am stuck trying to figure out how to make preg_match_all to do what I want... I want to match strings that look like <[someText]> Also, I would like to do this in a lazy fashion, so if a have a string like $myString = '<[someText]> blah blah blah <[someOtherText]> lala [doNotMatchThis] '; I would like to have 2 matches: '<[someText]>' and '<[someOtherText]>' as opposed to a single match '<[someText]> blah blah blah <[someOtherText]>' I am trying to

Java regex for removing all characters except a pattern

*爱你&永不变心* 提交于 2021-01-28 14:51:51
问题 I have a string including e-mail. There are probably extra characters before and / or after it. input examples: a1@b.com a2@b.com abcd efg x y z a3@b.com p q a4@b.com x z asd[x5@c.net]gh I want to remove the extra characters. Desired outputs: a1@b.com a2@b.com a3@b.com a4@b.com x5@c.net Valid characters are a-zA-Z0-9._ So there are probably invalid characters before and / or after e-mail. I tried this code to identify whether it is a correct email or not (this assumes that it is separated

Java regex for removing all characters except a pattern

让人想犯罪 __ 提交于 2021-01-28 14:42:05
问题 I have a string including e-mail. There are probably extra characters before and / or after it. input examples: a1@b.com a2@b.com abcd efg x y z a3@b.com p q a4@b.com x z asd[x5@c.net]gh I want to remove the extra characters. Desired outputs: a1@b.com a2@b.com a3@b.com a4@b.com x5@c.net Valid characters are a-zA-Z0-9._ So there are probably invalid characters before and / or after e-mail. I tried this code to identify whether it is a correct email or not (this assumes that it is separated

Java regex to match multiline records starting with fixed label

你。 提交于 2021-01-28 14:39:38
问题 Following is an example of a list of multiline records, each starting with a fixed string label ( LABEL ): <Irrelevant line> ... <Irrelevant line> LABEL ... ... ... LABEL ... ... ... LABEL ... ... ... LABEL ... ... ... Is there a Java regular expression that can much the above and extract each record, i.e. LABEL ... ... ... Also, is this the fastest way of extracting those records, or reading line-by-line and checking the start of the string would yield faster results? 回答1: To iterate over

Splitting String in regex with - as one word

余生颓废 提交于 2021-01-28 14:37:03
问题 I am trying to split a sentence with 32 chars in each group of regex. The sentence is split after the complete word if 32nd character is a letter in the word. When my input is a sentence which has "-" it splits that word too. This is the regex I am using (\b.{1,32}\b\W?) Input string: Half Bone-in Spiral int with dark Packd Smithfield Half Bone-in Spiral Ham with Glaze Pack resulting groups: Half Bone-in Spiral int with dark Packd Smithfield Half Bone- in Spiral Ham with Glaze Pack In above

Splitting String in regex with - as one word

时光毁灭记忆、已成空白 提交于 2021-01-28 14:34:27
问题 I am trying to split a sentence with 32 chars in each group of regex. The sentence is split after the complete word if 32nd character is a letter in the word. When my input is a sentence which has "-" it splits that word too. This is the regex I am using (\b.{1,32}\b\W?) Input string: Half Bone-in Spiral int with dark Packd Smithfield Half Bone-in Spiral Ham with Glaze Pack resulting groups: Half Bone-in Spiral int with dark Packd Smithfield Half Bone- in Spiral Ham with Glaze Pack In above

match home page url with regex

荒凉一梦 提交于 2021-01-28 14:17:48
问题 I want to match only the homepage of website www.mysite.com and any variations of it like mysite.com/?src=advert I have come up with ^https?:\/\/[^\/]+(\/(\?.*|index\.com(\?)?)?)?$ It matches www.mysite.com but I need it to match anything after /? as well www.mysite.com/? (and anything after question mark) I don't want to match mysite.com/product/.. 回答1: It seems you are looking for ^https?:\/\/(?:[^\/]+\.)?mysite\.com(?:\/(?:\?.*)?)?$ See the regex demo Details ^ - start of the string https?

Why does `/\:/u` throw an “invalid escape” error? [duplicate]

痴心易碎 提交于 2021-01-28 14:09:53
问题 This question already has an answer here : Firefox error: Unable to check input because the pattern is not a valid regexp: invalid identity escape in regular expression (1 answer) Closed 6 months ago . I have code like this: url.match(/^https?\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/ui) ESLint says Parsing error: Invalid regular expression: /^https?\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/: Invalid escape . I don’t see why this regular expression is wrong. How should I fix it? 回答1: Unnecessary escape sequences

Eliminate characters before a pattern in R [duplicate]

浪子不回头ぞ 提交于 2021-01-28 13:44:40
问题 This question already has answers here : Remove everything before period [duplicate] (2 answers) Closed 6 years ago . If I have the following dataframe: Fruits ONE_APPLE TWO_BANANAS THREE_ORANGES FOUR_PINAPPLES Is it possible to delete everything before the underscore, getting as a result: Fruits APPLE BANANAS ORANGES PINAPPLES There may be a pattern matching function but I haven't find the right one. Thanks for your support. 回答1: You could try the below gsub command to remove all the