word-boundary

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

依然范特西╮ 提交于 2019-12-01 16:41:18
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. Escape the backslashes 'foo'.match(new RegExp('\\bfoo\\b')); Don't wrap it in quotes... instead, do this:- 'foo'.match(new RegExp(/\bfoo\b/)) 来源: https://stackoverflow.com/questions/5024623/word-boundary-wont-match-the

How to find a word within text using XSLT 2.0 and REGEX (which doesn't have \\b word boundary)?

℡╲_俬逩灬. 提交于 2019-12-01 13:12:05
I am attempting to scan a string of words and look for the presence of a particular word(case insensitive) in an XSLT 2.0 stylesheet using REGEX. I have a list of words that I wish to iterate over and determine whether or not they exist within a given string. I want to match on a word anywhere within the given text, but I do not want to match within a word (i.e. A search for foo should not match on " foo d" and a search for bar should not match on "re bar "). XSLT 2.0 REGEX does not have a word boundary( \b ), so I need to replicate it as best I can. You can use alternation to avoid repetition

Matching word boundary with Bash regex

◇◆丶佛笑我妖孽 提交于 2019-12-01 10:51:04
I would like to match the following expression in bash: ^.*(\b((720p)|(1080p)|(((br)|(hd)|(bd)|(web)|(dvd))rip)|((x|h)264)|(DVDscr)|(xvid)|(hdtv)|(ac3)|(s[0-9]{2}e[0-9]{2})|(avi)|(mp4)|(mkv)|(eztv)|(YIFY))\b).*$ Really all I want to know is whether one of the words of the string tested is one of the words described in this regex ( 720p , 1080p , brrip , ...). And there seems to be an issue with the word boundaries. The test I use is [[ $name =~ $re ]] && echo "yes" where $name is any string and $re is my regex expression. What am I missing? \b is a PCRE extension; it isn't available in POSIX

Javascript RegExp and boundaries

不想你离开。 提交于 2019-12-01 08:53:37
问题 A colleague asked me about a Regular expression problem, and I can't seem to find and answer for him. We're using boundaries to highlight certain lengths of text in a text editor, but here's some sample code that shows the problem: <script type="text/javascript"> var str = "Alpha , Beta, Gamma Delta Epsilon, AAlphaa, Beta Alpha<br/>"; var rx = new RegExp('\bAlpha\b','gim'); document.write(str.replace(/\b(Alpha)\b/gim, '-- $1 --')); document.write(str.replace(rx, '== $1 ==')); </script> The

Regex difference between word boundary end and edge

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 08:50:45
问题 The R help file for regex says The symbols \< and \> respectively match the empty string at the beginning and end of a word. The symbol \b matches the empty string at the edge of a word What is the difference between an end and an edge (of a word)? 回答1: The difference between the \b and \< / \> is that \b can be used in PCRE regex patterns (when you specify perl=TRUE ) and ICU regex patterns ( stringr package). > s = "no where nowhere" > sub("\\<no\\>", "", s) [1] " where nowhere" > sub("\\

Matching word boundary with Bash regex

旧巷老猫 提交于 2019-12-01 08:19:25
问题 I would like to match the following expression in bash: ^.*(\b((720p)|(1080p)|(((br)|(hd)|(bd)|(web)|(dvd))rip)|((x|h)264)|(DVDscr)|(xvid)|(hdtv)|(ac3)|(s[0-9]{2}e[0-9]{2})|(avi)|(mp4)|(mkv)|(eztv)|(YIFY))\b).*$ Really all I want to know is whether one of the words of the string tested is one of the words described in this regex ( 720p , 1080p , brrip , ...). And there seems to be an issue with the word boundaries. The test I use is [[ $name =~ $re ]] && echo "yes" where $name is any string

How to use word boundaries in awk without using match() function?

有些话、适合烂在心里 提交于 2019-12-01 05:56:16
问题 I want to add word boundaries to this awk command: awk '{$0=tolower($0)};/wordA/&&/wordB/ { print FILENAME ":" $0; }' myfile.txt I tried adding \y at left and right of wordA and wordB but it didn't work in my tests. I tried this: /\ywordA\y/&&/\ywordB\y/ Thanks all! (ps: I'm new to awk so I was trying to avoid the match() function.) 回答1: You want to use gawk instead of awk: gawk '{$0=tolower($0)};/\ywordA\y/&&/\ywordB\y/ { print FILENAME ":" $0; }' myfile.txt will do what you want, if your

Regular expression to match boundary between different Unicode scripts

馋奶兔 提交于 2019-12-01 04:18:53
Regular expression engines have a concept of "zero width" matches, some of which are useful for finding edges of words: \b - present in most engines to match any boundary between word and non-word characters \< and \> - present in Vim to match only the boundary at the beginning of a word, and at the end of a word, respectively. A newer concept in some regular expression engines is Unicode classes. One such class is script, which can distinguish Latin, Greek, Cyrillic, etc. These examples are all equivalent and match any character of the Greek writing system: \p{greek} \p{script=greek} \p

A Viable Solution for Word Splitting Khmer?

冷暖自知 提交于 2019-11-30 11:25:48
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): ចូរសរសើរដល់ទ្រង់ដែលទ្រង់បានប្រទានការទាំងអស់នោះមកដល់រូបអ្នកដោយព្រោះអង្គព្រះយេស៊ូវ ហើយដែលអ្នកមិនអាចរកការទាំងអស់នោះដោយសារការប្រព្រឹត្តរបស់អ្នកឡើយ។ The goal of creating a viable solution that splits Khmer words is twofold: it

Javascript Regex Word Boundary with optional non-word character

做~自己de王妃 提交于 2019-11-30 09:49:39
问题 I am looking to find a keyword match in a string. I am trying to use word boundary, but this may not be the best case for that solution. The keyword could be any word, and could be preceded with a non-word character. The string could be any string at all and could include all three of these words in the array, but I should only match on the keyword: ['hello', '#hello', '@hello']; Here is my code, which includes an attempt found in post: let userStr = 'why hello there, or should I say #hello