word-boundary

PHP Regex Word Boundary exclude underscore _

白昼怎懂夜的黑 提交于 2021-02-04 15:45:36
问题 I'm using regex word boundary \b, and I'm trying to match foo in the following $sentence but the result is not what I need, the underscore is killing me, I want underscore to be word boundary just like hyphen or space: $sentence = "foo_foo_foo foo-foo_foo"; X X X YES X X Expected: $sentence = "foo_foo_foo foo-foo_foo"; YES YES YES YES YES YES My code: preg_match("/\bfoo\b/i", $sentence); 回答1: You would have to create DIY boundaries. (?:\b|_\K)foo(?=\b|_) 回答2: Does this do what you want?: preg

Word boundaries not matching when the word starts or ends with special character like square brackets

三世轮回 提交于 2020-04-28 12:57:33
问题 I want to replace string which is a square bracket with another number. I am using regex replace method. Sample input: This is [test] version. Required output (replacing "[test]" with 1.0): This is 1.0 version. Right now regex is not replacing the special character. Below is the code which I have tried: string input= "This is [test] version of application."; string stringtoFind = string.Format(@"\b{0}\b", "[test]"); Console.WriteLine(Regex.Replace(input, stringtoFind, "1.0")); There may be

Word boundaries not matching when the word starts or ends with special character like square brackets

青春壹個敷衍的年華 提交于 2020-04-28 12:57:05
问题 I want to replace string which is a square bracket with another number. I am using regex replace method. Sample input: This is [test] version. Required output (replacing "[test]" with 1.0): This is 1.0 version. Right now regex is not replacing the special character. Below is the code which I have tried: string input= "This is [test] version of application."; string stringtoFind = string.Format(@"\b{0}\b", "[test]"); Console.WriteLine(Regex.Replace(input, stringtoFind, "1.0")); There may be

A Viable Solution for Word Splitting Khmer?

狂风中的少年 提交于 2019-12-30 03:55:13
问题 I am working on a solution to split long lines of Khmer (the Cambodian language) into individual words (in UTF-8). Khmer does not use spaces between words. There are a few solutions out there, but they are far from adequate (here and here), and those projects have fallen by the wayside. Here is a sample line of Khmer that needs to be split (they can be longer than this): ចូរសរសើរដល់ទ្រង់ដែលទ្រង់បានប្រទានការទាំងអស់នោះមកដល់រូបអ្នកដោយព្រោះអង្គព្រះយេស៊ូវ

Regex word boundary issue when angle brackets are adjacent to the boundary

给你一囗甜甜゛ 提交于 2019-12-28 06:53:08
问题 Regex: \b< low="" number="" low="">\b Example string: <b22>Aquí se muestran algunos síntomas < low="" number="" low=""> tienen el siguiente aspecto.</b22> I'm not sure why the word boundary between síntomas and < is not being found. Same problem exists on the other side between > and tienen Suggestions on how I might more properly match this boundary? When I give it the following input, the Regex matches as expected: Aquí se muestran algunos síntomas< low="" number="" low="">tienen el

MySQL REGEXP matches a boundary word only but excluding the match in html tags

≡放荡痞女 提交于 2019-12-25 08:57:28
问题 Following this question and answer, I still have a bit trouble in the result I get, For instance, REGEXP '>[^<]*lau[[:>:]]' will match ' lau ' only but not ' laurence ' which is correct. REGEXP '>[^<]*men[[:>:]]' will match ' empowerment ' and ' women ' which are not what I am after. REGEXP '( |>|$)home( |<|$)' will match ' home ' only but not ' home! ' which it should . How can match these correctly? For instance, Home - match HOME - match welcome home! - match home is far! - match hometown

Do word boundaries work on symbol characters?

天涯浪子 提交于 2019-12-25 04:17:36
问题 I'm trying to implement word boundaries in my emoticons feature for a chat. But for some reason I can't seem to get the word boundaries to work. I am new to regex. So when I do: var reg = /\b\Hi\b/gi; var str = 'HiHiHi Hi HiHiHi Hi'; alert(str.replace(reg, '')); This happens: Jsfiddle It actually works fine, and does remove those 2 Hi's that are standing alone. But when I change the reg to an escaped smiley and then change the string: var reg = /\b\:\)\b/gi; var str = 'HiHi:) :) HiHiHi :)';

Word Boundary Regular Expression Unless Inside HTML Tag

时光怂恿深爱的人放手 提交于 2019-12-24 10:48:12
问题 I have a regular expression using word boundaries that works exceedingly well... ~\b('.$value.')\b~i ...save for the fact that it matches text inside HTML tags (i.e. title="This is blue!" ). It's a problem because I'm doing text substitution on anything the regex matches, then making tooltips appear using those title tags. So, as you can imagine, it's substituting text inside the title and breaking the HTML of the tooltip. For example, what should be: <span class="blue" title="This is blue!"

Java Regex Word Boundaries

醉酒当歌 提交于 2019-12-19 18:15:08
问题 Hi I have the following code which is meant to find the word "is" but not when it is within another string so the word "this" should not return a match so I use \b. But the following code does not find a match and I cant figure out why? public static void main(String[] args) { String a = "This island is beautiful."; Pattern p = Pattern.compile("\bis\b"); Matcher m = p.matcher(a); while(m.find()){ System.out.println(a.substring(m.start(), m.end())); } } 回答1: Double escape it: Pattern p =

Word boundary won't match the beginning or end in Javascript

对着背影说爱祢 提交于 2019-12-19 17:44:36
问题 I'm getting unexpected results with this code: 'foo'.match(new RegExp('\bfoo\b')); // Returns null Why is this returning null while this one returns "foo"? 'foo'.match(new RegExp('foo')); // Returns "foo" Doesn't a word boundary marker match the beginning and end as well? EDIT: I need the regular expression itself to be a string because I am injecting variables into it. 回答1: Escape the backslashes 'foo'.match(new RegExp('\\bfoo\\b')); 回答2: Don't wrap it in quotes... instead, do this:- 'foo'