This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex - match single character at end of a line

 
Ron Landreth
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a list of words, one to each line, and each word has a single character at the end that denotes its part of speech. Therefore, I'm trying to write a regular expression that will match a single character at the end of line, so I can parse through this data.

I can't just use something like [N$] because it will just match the first 'N' from the end of the line, not just lines that end in N. So I want something that will match a single character at the end of a line.

So if my data contained something like:
BounceN
BouncerV

I would want the regular expression to match 'N' at the end of a line to match just "BounceN" and not "BouncerV".

Thanks for you time, and thanks in advance to anyone that can help.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cowboys,

Ron Landreth posted November 03, 2006 10:57 PM
I would want the regular expression to match 'N' at the end of a line to match just "BounceN" and not "BouncerV".


You will need the greedy quantifier .* followed by an N$.

.*N$

means any number of any characters (including zero) followed by an N at the end of the line, and process whole string first.

It will find in the sequence "BouNcerN" only the whole bouncer, not the "BouN" and not the "cerN".


Yours,
Bu.
[ November 04, 2006: Message edited by: Burkhard Hassel ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic