regex

Java regex: why numbers [0-9], comma etc. is not an unicode?

血红的双手。 提交于 2021-02-05 12:28:04
问题 class Test { public static void main (String[] args) { String regex = "\\p{L}"; System.out.println("0".matches(regex)); } } The code above prints false, but I was expecting true because isn't ASCII a subset of unicode ? "0" is part of ASCII, so I think it should also belongs to a unicode letter. Also, comma, period etc prints "false" true, while "a" will print true. 回答1: It is because \\p{L} matches a Unicode letter and you're matching a digit. You can use: [\\p{L}\\p{Nd}.,] to match a

Parse shortcodes in JavaScript [closed]

谁说胖子不能爱 提交于 2021-02-05 12:26:29
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . Improve this question I'm looking for a way to parse shortcodes in a string, which will return their ids and values in an array of objects like the following: var str = 'First shortcode is [fraction num="1" denom="2"] and the second is [square-root content="456"] which we will pass into a function

Parse shortcodes in JavaScript [closed]

☆樱花仙子☆ 提交于 2021-02-05 12:25:51
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . Improve this question I'm looking for a way to parse shortcodes in a string, which will return their ids and values in an array of objects like the following: var str = 'First shortcode is [fraction num="1" denom="2"] and the second is [square-root content="456"] which we will pass into a function

Regex for phone number with country code [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-05 12:24:54
问题 This question already has answers here : How to validate phone numbers using regex (42 answers) Closed 2 years ago . I am trying to write regex for a phone number with a country code. The number is supposed to begin with a "+" sign. I tried and solved the first part for + sign. ^\+\d{12}$ The issue here is that it will only work for 12 digits long number starting with + . How can I make it work for any number of digits in range of <= 15 ? 回答1: Just change {12} to + in your regex, so that it

Javascript Regex to look for characters and wrap text with span dynamically

ぃ、小莉子 提交于 2021-02-05 12:24:48
问题 So I'm trying to replace this: <h1>My Title <INTRO></h1> With this: <h1>My Title <span><INTRO></span></h1> But... In a way that dynamically looks for all instances of text wrapped in < ... > and wraps that in span tags. Something like the code below, but I can't get the regex right. str = str.replace(/(?<=<)\r\n(?=>)/, "<span>$1</span>"); 回答1: You can use the following regex: (<[\s\S]*?>) And replace with: <span>$1</span> See DEMO Js Code: var str = "<h1>My Title <INTRO></h1>" str = str

Javascript Regex to look for characters and wrap text with span dynamically

只谈情不闲聊 提交于 2021-02-05 12:22:33
问题 So I'm trying to replace this: <h1>My Title <INTRO></h1> With this: <h1>My Title <span><INTRO></span></h1> But... In a way that dynamically looks for all instances of text wrapped in < ... > and wraps that in span tags. Something like the code below, but I can't get the regex right. str = str.replace(/(?<=<)\r\n(?=>)/, "<span>$1</span>"); 回答1: You can use the following regex: (<[\s\S]*?>) And replace with: <span>$1</span> See DEMO Js Code: var str = "<h1>My Title <INTRO></h1>" str = str

preg_match(): Unknown modifier '/' [duplicate]

落花浮王杯 提交于 2021-02-05 12:21:52
问题 This question already has answers here : Warning: preg_replace(): Unknown modifier (3 answers) Closed 1 year ago . When i give this regular expression for validating URL it shows error... preg_match(): Unknown modifier '/' in C:\wamp64\www\php\Form Validation\form.php on line 36 if(!preg_match("/%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x

PHP preg_replace skipping where match overlaps

江枫思渺然 提交于 2021-02-05 12:21:07
问题 I've been Googling this regex behavior all afternoon. $str = ' b c d w i e f g h this string'; echo preg_replace('/\s[bcdefghjklmnopqrstuvwxyzBCDEFGHJKLMNOPQRSTUVWXYZ]{1}\s/', ' ', $str); I want to remove all instances of a single character by itself (except for A and I) and leave one space in its place. This code appears to work on every other match. I suspect this is because the matches overlap each other. I suspect a lookaround would be appropriate here, but I've never used them before and

How to insert the whole matched text in the replacement in Perl?

回眸只為那壹抹淺笑 提交于 2021-02-05 12:20:48
问题 I want to add a string ( A ) after all specific other strings ( bbc ). So, I match bbc and want to replace it with itself with A appended ( 'aabbcc' => 'aabbcAc' ). Is there a replacement back-reference that gets substituted with the whole match? $0 doesn't seem to work – its content is always "-e", for some reason: $ echo 'aabbcc' | perl -p -e 's/bbc/$0A/g' aa-eAc 回答1: Use $& , see http://perldoc.perl.org/perlvar.html echo 'aabbcc' | perl -p -e 's/bbc/$&A/g' aabbcAc 来源: https://stackoverflow

PHP preg_replace skipping where match overlaps

帅比萌擦擦* 提交于 2021-02-05 12:20:08
问题 I've been Googling this regex behavior all afternoon. $str = ' b c d w i e f g h this string'; echo preg_replace('/\s[bcdefghjklmnopqrstuvwxyzBCDEFGHJKLMNOPQRSTUVWXYZ]{1}\s/', ' ', $str); I want to remove all instances of a single character by itself (except for A and I) and leave one space in its place. This code appears to work on every other match. I suspect this is because the matches overlap each other. I suspect a lookaround would be appropriate here, but I've never used them before and