What are non-word boundary in regex (\B), compared to word-boundary?
What are non-word boundary in regex (\B), compared to word-boundary?
19.3k Views Asked by DarkLightA At
2
There are 2 best solutions below
0
derenio
On
The basic purpose of non-word-boundary is to created a regex that says:
if we are at the beginning/end of a
word char(\w=[a-zA-Z0-9_]) make sure the previous/next character is also aword char,e.g.:
"a\B."~"a\w":"ab","a4","a_", ... but not"a ","a."if we are at the beginning/end of a
non-word char(\W=[^a-zA-Z0-9_]) make sure the previous/next character is also anon-word char,e.g.:
"-\B."~"-\W":"-.","- ","--", ... but not"-a","-1"
For word-boundary it's similar but instead of making sure that the adjacent characters are of the same class (word char/non-word car) they need to differ, hence the name word's boundary.
Related Questions in JAVASCRIPT
- Angular Show All When No Filter Is Supplied
- Why does a function show up as not defined
- I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
- Set "More" "Less" font size
- Using pagination on a table in AngularJS
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- State with different subviews
- Ajax jQuery firing multiple time display event for the same result
- Getting and passing MVC Model data to AngularJS controller
- Disable variable in eval
- javascript nested loops waiting for user input
- .hover() seems to overwrite .click()
- How to sort a multi-dimensional array by the second array in descending order?
- How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
Related Questions in REGEX
- Check for numeric value with optional commas javascript
- CSV to XML XSLT: How to quote excape
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- Max 3 digits, up to 3 decimals
- Regex for SQL insert query
- Javascript Regex to get specific string from two differently-formatted text blocks
- JavaScript differences beetween new Regex('regex', 'flags') and /regex/flags
- Java replace every Nth specific character (e.g. space) in String
- c# regex spain mobile phone
- Perl Regex: Merge multiple one-character substrings
- Using .css("background-color") for comparison jQuery/Js
- Unexpected NoReverseMatch error when using include() in urls patterns
- RegEx for all the javascript code except comments
- Regex: how to separate username:password?
- Customising a RegExp for international phone numbers
Related Questions in WORD-BOUNDARY
- Substring[whole word] check using a string variable
- Word boundary regex issue
- Is there a unicode capable alternative for word boundary escape sequence "\b"?
- JAVA REGEX :: Could you explain this?
- Regex word boundary not recognizing punctuation
- word boundary and pattern quote not working
- PHP using preg_replace to highlight string that is part of a word
- what is wrong with my word boundary regex?
- Word boundary won't match the beginning or end in Javascript
- Regex word boundary alternative for lex
- Regex word boundary issue when angle brackets are adjacent to the boundary
- vimscript match combine \V with word boundaries
- Matching word boundary with Bash regex
- Javascript regular expression for searching word boundaries in Unicode string
- Is there an alternative to \b and/or negative lookahead for JFLEX?
Related Questions in BOUNDARY
- Create mask from bwtraceboundary in Matlab
- HttpContent boundary double quotes
- Regex pass dynamic values with boundry
- Model View Controller vs Boundary Control Entity
- r checking if row elements are within bounds
- How to find string(conaining special char) from regular expression with boundary condition
- How to detect the boundary of an uiimage
- HttpClient setting boundary with content-type
- heat transfer for spherical coordinates boundary conditions implementation
- Align color fields and labels in discrete colorbar
- Android: My LinearLayout expands out of its parent scrollview
- Window boundaries in Pygame are not working
- Boundary in Powell method Scipy
- Free boundary conditions in MATHEMATICA - is this right? Second opinion
- Efficient segment boundary marking after segmentation of an image
Related Questions in WORD-BOUNDARIES
- stop words removal using arrays c#
- word boundaries in irb
- WordPress query search 's' exact word
- Javascript RegEx safari issue
- Javascript RegEx UTF-8
- Counting full, case insensitive words using scrapy and regular expression
- Word boundry not working in MySQL 8.0.16 REGEX?
- Audio mining for words boundaries
- Regular expression to match boundary between different Unicode scripts
- Alignment of C structure
- What are non-word boundary in regex (\B), compared to word-boundary?
- How to find a word containing bracket "(" and using word boundaries?
- regex for dot before optional word terminating numbers
- A regular expression for \b
- Word boundaries with extented set of characters
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
A word boundary (
\b) is a zero width match that can match:\w) and a non-word character (\W) orIn Javascript the definition of
\wis[A-Za-z0-9_]and\Wis anything else.The negated version of
\b, written\B, is a zero width match where the above does not hold. Therefore it can match:For example if the string is
"Hello, world!"then\bmatches in the following places:And
\Bmatches those places where\bdoesn't match: