wood burning stoves 2.0*
The moose likes Java in General and the fly likes Regex - match single character at end of a line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regex - match single character at end of a line" Watch "Regex - match single character at end of a line" New topic
Author

Regex - match single character at end of a line

Ron Landreth
Greenhorn

Joined: Oct 04, 2006
Posts: 3
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

Joined: Aug 25, 2006
Posts: 1274
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 ]

all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex - match single character at end of a line
 
Similar Threads
Need help programming regular expressions
A small problem in replaceAll
to read lines inside brackets
trouble retrieving html of all web sites
Regular Expressions on a .csv file