Skip to content Skip to sidebar Skip to footer

Javascript / Regex: Delete A Specific Text (word) Starting With A Specific Letter Inside A String With Words Separated By Spaces

I know this can quickly be done with Regex: I got string like: 'Alpha OmegaS Sheol Gehena GSSaga Serekali' I wanna remove words that Starts with s. So I should have: 'Alpha Om

Solution 1:

How about:

str.replace(/\bs\S+/ig,"")

Explanation:

NODE                     EXPLANATION
----------------------------------------------------------------------
  \b                       the boundary between a word char (\w) and
                           something that isnot a word char----------------------------------------------------------------------
  s                        's'----------------------------------------------------------------------
  \S+                      non-whitespace (all but \n, \r, \t, \f,
                           and " ") (1or more times (matching the
                           most amount possible))
----------------------------------------------------------------------

i isforcase-insensitive
g isforglobal

Post a Comment for "Javascript / Regex: Delete A Specific Text (word) Starting With A Specific Letter Inside A String With Words Separated By Spaces"