CornerPixel Blog RSS 2.0

# Friday, September 04, 2009

In JavaScript, a regular expression is written in the form of /pattern/modifiers where "pattern" is the regular expression itself, and "modifiers" are a series of characters indicating various options. The "modifiers" part is optional.

    * /g enables "global" matching. When using the replace() method, specify this modifier to replace all matches, rather than only the first one.
    * /i makes the regex match case insensitive.
    * /m enables "multi-line mode". In this mode, the caret and dollar match before and after newlines in the subject string.

You can combine multiple modifiers by stringing them together as in /regex/gim.

Since forward slashes delimit the regular expression, any forward slashes that appear in the regex need to be escaped. For example, the regex 1/2 is written as /1\/2/ in JavaScript.

As with anything, you can find much more information about JavaScript on the web if you Google or Bing it. 

Friday, September 04, 2009 2:30:01 PM (Pacific Standard Time, UTC-08:00)

#       Comments [0] - Trackback

Code | JavaScript | jQuery

Comments are closed.

Archive

<September 2009>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Email Subscription

Sign up to get the CornerPixel Blog delivered to your email.

About the Author

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In

Statistics

Total Posts: 52
This Year: 3
This Month: 0
This Week: 0
Comments: 28