regex

How to replace text with a regex pattern and integrate a counter in the replacement text?

牧云@^-^@ 提交于 2021-02-05 10:00:18
问题 function parse($string){ $counter = 0; $string = preg_replace("_\[b\](.*?)\[/b\]_si", '<span class="b">'. $counter .'. $1</span>', $string, -1, $counter); return $string; } I'm trying to make a ubb parser, that parses tags and put the counting in front of it: [b]Hey[/b] [b]Hello[/b] Should return this: <span class="b">1. Hey</span> <span class="b">2. Hello</span> But is returning this: <span class="b">1. Hey</span> <span class="b">1. Hello</span> So beside the function above, I've tried this:

Regex match strings between asterisks

北慕城南 提交于 2021-02-05 09:48:24
问题 I have a string like this: var s = "*string1* *string2* *string3*"; I'm trying to create a regex which returns an array of the three strings between * How can I do that? I tried using this but I'm not sure if it is correctly escaped s.match("\*(.*)\*") Thanks 回答1: You need to use lazy quantifier ? here and also escape \ Like this \*(.*?)\* Regex101 Demo Without using lazy quantifier you can do something like this. \*[^*]+\* This will match a * everything until a * * . Regex101 Demo Use \\

Regex match strings between asterisks

依然范特西╮ 提交于 2021-02-05 09:48:10
问题 I have a string like this: var s = "*string1* *string2* *string3*"; I'm trying to create a regex which returns an array of the three strings between * How can I do that? I tried using this but I'm not sure if it is correctly escaped s.match("\*(.*)\*") Thanks 回答1: You need to use lazy quantifier ? here and also escape \ Like this \*(.*?)\* Regex101 Demo Without using lazy quantifier you can do something like this. \*[^*]+\* This will match a * everything until a * * . Regex101 Demo Use \\

Reg-Ex for JCB Credit Card Validation

a 夏天 提交于 2021-02-05 09:45:53
问题 I need a reg-ex for JCB card validation with this rule, (Reference for JCB format) First four digits must be 3088, 3096, 3112, 3158, 3337, or the first eight digits must be in the range 35280000 through 35899999. Valid length: 16 digits. Many posts are found with Regex ^(?:2131|1800|35\d{3})\d{11}$ referring to post1, post2 and post3. I am building a credit card payment module using Authorize.Net.But the Authorize.Net test JCB credit card validation fails for above Regex (^(?:2131...). But

Java regex for remove no digit chracter except decimal point

為{幸葍}努か 提交于 2021-02-05 09:44:43
问题 I have following strings: S/. 05.56 S/. 0.0 S/. 0.00 S/. 90.10 S/. 01.23 S/. 1.00 S/.1.80 $/.9.80 $/. 10.80 $/. 89.81 $ 89.81 I need this output 05.56 0.0 0.00 90.10 01.23 1.00 1.80 9.80 10.80 89.81 I need to remove all non-digit character before first number, Then regex haven't to remove decimal point I tried this regex but doesn't work: e.replaceAll("[a-zA-z](/.)( )*", ""); //don't remove $ e.replaceAll("[^0-9.]", ""); //This show .3.4 I need remove the first point decimal I need to remove

Regex to match time

北城以北 提交于 2021-02-05 09:44:38
问题 I want my users to be able to enter a time form. If more info necessary, users use this to express how much time is needed to complete a task, and it will be saved in a database if filled. here is what I have: /^$|^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/ It matches an empty form or 01:30 and 01:30:00 formatted times. I really won't need the seconds as every task takes a minute at least, but I tried removing it and it just crashed my code and removed support for empty string.. I

Java regex for remove no digit chracter except decimal point

蹲街弑〆低调 提交于 2021-02-05 09:44:27
问题 I have following strings: S/. 05.56 S/. 0.0 S/. 0.00 S/. 90.10 S/. 01.23 S/. 1.00 S/.1.80 $/.9.80 $/. 10.80 $/. 89.81 $ 89.81 I need this output 05.56 0.0 0.00 90.10 01.23 1.00 1.80 9.80 10.80 89.81 I need to remove all non-digit character before first number, Then regex haven't to remove decimal point I tried this regex but doesn't work: e.replaceAll("[a-zA-z](/.)( )*", ""); //don't remove $ e.replaceAll("[^0-9.]", ""); //This show .3.4 I need remove the first point decimal I need to remove

split one line regex in a multiline regexp in perl

浪尽此生 提交于 2021-02-05 09:43:25
问题 I have trouble spliting my regex in multiple line. I want my regex to match the line given: * Code "l;k""dfsakd;.*[])_lkaDald" So I created this regex which work: my $firstRegexpr = qr/^\s*\*\s*Code\s+\"(?<Code>((\")*[^\"]+)+)\"/x; But now I want to split it in multiline like this(and want it to match the same thing!): my $firstRegexpr = qr/^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\"/x; I read about this, but I have trouble using it: / ^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\" /x My last

split one line regex in a multiline regexp in perl

删除回忆录丶 提交于 2021-02-05 09:42:36
问题 I have trouble spliting my regex in multiple line. I want my regex to match the line given: * Code "l;k""dfsakd;.*[])_lkaDald" So I created this regex which work: my $firstRegexpr = qr/^\s*\*\s*Code\s+\"(?<Code>((\")*[^\"]+)+)\"/x; But now I want to split it in multiline like this(and want it to match the same thing!): my $firstRegexpr = qr/^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\"/x; I read about this, but I have trouble using it: / ^\s*\*\s*Code\s+\" (?<Code>((\")*[^\"]+)+)\" /x My last

MongoDB RegEx not working

淺唱寂寞╮ 提交于 2021-02-05 09:40:45
问题 I'm trying to return documents that whose obsNum field starts with 1. . I have written the following RegEx to filter out those documents however, it returns all the documents that start with 1 Observations.getObservationsModelObject().find({ "ageGroup": ageGroup, "obsNum": { $regex: '^\s*1\.' } }, function(err, foundData) {}); What am I doing wrong? This RegEx '^\s*1\.' is returning the following instead of returning on 1.3, 1.1 & 1.2: obsNum: 1.3 obsNum: 1.1 obsNum: 1.2 obsNum: 123 obsNum: