Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: match word that ends with "Id"

Tags:

c#

regex

I need help putting together a regex that will match word that ends with "Id" with case sensitive match.

like image 405
epitka Avatar asked Feb 12 '10 20:02

epitka


People also ask

How do you match a word in regex?

To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string).

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.

What is D and D in regex?

In regex, the uppercase metacharacter is always the inverse of the lowercase counterpart. \d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ).


2 Answers

Try this regular expression:

\w*Id\b 

\w* allows word characters in front of Id and the \b ensures that Id is at the end of the word (\b is word boundary assertion).

like image 118
Gumbo Avatar answered Sep 26 '22 22:09

Gumbo


Gumbo gets my vote, however, the OP doesn't specify whether just "Id" is an allowable word, which means I'd make a minor modification:

\w+Id\b 

1 or more word characters followed by "Id" and a breaking space. The [a-zA-Z] variants don't take into account non-English alphabetic characters. I might also use \s instead of \b as a space rather than a breaking space. It would depend if you need to wrap over multiple lines.

like image 30
BenAlabaster Avatar answered Sep 25 '22 22:09

BenAlabaster