Contents tagged with Regex
-
Regex Reminders - A brief explanation
Over the next couple weeks I'm going to post a series of regular expression examinations; each one will be a code intensive focus on a certain operations such as "Replace" or "Working with Matches and Groups". The goal of the Regex Reminders is to end up with a lot of code for working with regex's that people can just use to "grab and go". The series will also spend time looking at common regex techniques such as alternation and grouping techniques.
-
Redefining Boundaries - \b and \B
\b and \B are useful metacharacters; they provide a simple syntax to easily find items that exist around word boundaries (or, in the case of \B, non-word boundaries). For example, to find the word "per" you can wrap the actual text inside \b's to ensure that the phrase is not inadvertantly matched when found inside of "person" or "Supercalif", i.e.:
-
RegexLib.com RSS feeds
As mentioned by Roy I've altered the main RegexLib.com Rss feed so that the feed title displays more useful information. I've also created a new feed to display the most recent comments that have been entered by users against patterns.
-
\G - match at the end of the previous match.
Over the next few days I'd like to spend a bit of time looking at using \G in the .NET "flavour" of regular expressions. I'd love to hear from anyone that has *had* to use \G in a real-world application (.NET only).
-
DaysOfTheWeek regex
Michael Ash has done some neat work on the DaysOfTheWeek regex:
-
Conditional matching
Today, while proving what a prat I am, I added some conditional testing to a pattern which I had written. Conditional matching allows you to perform a test based on if...then[...else] logic. The syntax is (?if then | else ) - with the 'else' part being optional.
-
Using backreferences in a Match
You can reference backreferences within a regular expression to keep the length and complexity of patterns to a minimum. Backreferences can be referenced with the \1..\N or \k'name' notation. To highlight where this is useful consider a simple-minded pattern for matching Dates. Dates can (potentially) be delimited by either a space, a dot, a hyphen or a slash - that is, any of the following might be allowed:
-
Find words NOT IN text
I'm currently writing a series of articles (that will hopefully get published {grin}) titled "Regex Reminders" that will provide dozens of code snippets that demonstrate how to perform common - and some not-so-common - operations using regex.
-
Date Regex - [ Note To Self ]
While scouring through the pile of comments that have been left on RegexLib.com I noticed a pattern which purports to validate Dates in dmy format. I couldn't help but notice that all of the comments which have been left have been highly favourable of this expression.
-
Displaying User Input - Part 2
Back in June I posted a cryptic little entry that highlighted a potential issue that can arise when displaying user input.