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
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in REGEX
- Python and regex, can't understand why some words are left out of the match
- Special access rule in an .htaccess file for IP addresses, authorized only for one directory structure
- regex working not as expected javascript, displays wrong values
- Clarity on how can `.*` match all strings?
- IIS Rewrite Module exclude bots but allow GoogleBot
- Regex skipping delimiter is there is / before it
- How to ignore case in regexp mapping in a .htaccess rewrite rule?
- Select all lines after last occurrence of a certain character
- Segregate class names using regular expresions
- Regex to match binary literal number in re2c format
- why the perl regular expression is not identifying the value
- Trying to run subprocess commands with carriage returns and newlinees
- `Backward slash + b` does not work as expected on regex
- Extract 15 words before and 8 words after each 9digit number from a text file using regular expressions in python
- How to migrate this regex to JavaScript
Related Questions in WORD-BOUNDARY
- Automatic Word Boundary Detection for German
- What is the equivalent regex expression \b written using ^ and $?
- Word Boundaries in R for Word Filtering
- Negative Lookahead & Lookbehind with Capture Groups and Word Boundaries
- Split a string by max characters length, word aware - but without capturing whitespaces
- Regex word-boundary not working as expected
- Word boundary between ASCII and Unicode letters in Python3
- Java regex - exclude newline from word boundary
- word matching with boundary not works
- Word boundaries to match strings containing dots (.) at begin/end
- Is there an alternative to \b and/or negative lookahead for JFLEX?
- Hive rlike matching word boundary
- How this mixed-character string split on unicode word boundaries
- Emacs search words with underscores not considered as word boundaries
- Is it possible to modify word character class or \b boundary to exclude underscore character?
Related Questions in BOUNDARY
- Constraint two coaxial rods for FEA using ABAQUS CAE, where the outer and inner can rotate vertically and also the inner one can move axially
- How can I implement an specific boundary condition in COMSOL?
- IDW Interpolation of point rainfall data using Python
- Find a concave hull of an array of integer points on a grid
- Lower and Upper bound in postgresql
- solve pde with BC in python
- Pyspark Window using dates as boundary
- Outline of the Ear needed using "boundary" function of matlab
- f=sym('f',[1 4]) q=zeros(1,4) for i=0:3 f(1,i+1) = (@(x)(exp(-x).*(x.^0.5).*x.*laguerreL(i,0.5,x))) %g(1,i+1)=quadgk(f(1,i+1),0,1) end
- Bounfary Folding Hash Function
- How can I plot a colormap with discrete intervals in xarray and avoid Error Passing a Normalize instance simultaneously with vmin/vmax not supported
- How to write the constraints for scipy SLSQP properly
- How to implement Conway’s Game of Life using a quadtree in Java?
- Maximum value for Julia integer types
- Filling objects based on the boundaries
Related Questions in WORD-BOUNDARIES
- Counting full, case insensitive words using scrapy and regular expression
- WordPress query search 's' exact word
- regex for dot before optional word terminating numbers
- Javascript RegEx safari issue
- Word boundry not working in MySQL 8.0.16 REGEX?
- Word boundaries not matching when the word starts or ends with special character like square brackets
- Javascript RegEx UTF-8
- Non-capturing group matching whitespace boundaries in JavaScript regex
- Oracle regexp_like word boundaries multiple words workaround
- Get most matched result on top in mysql LIKE query
- What are the most efficient ways to write regex with boundary matching in Java?
- Regex pattern to find pec+
- Java RegEx Syntax with Word Boundaries?
- Is it possible to get word boundaries of SE Asian scripts via JavaScript?
- stop words removal using arrays c#
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 # Hahtags
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: