user3730931
user3730931

Reputation: 31

Regex get value up until a character

An example input would be;

$500 has been received from username.

So far I have this regex string;

$ \\$(\\d+\\.?\\d*) has been received from

This should extract the balance (If I am correct?) The issue is, I cannot think of a solution as-to how to get the username. The username string is alpha-numerical so cannot contain fullstops. What would I use to get all characters after the ' ' up until the '.'?

Thanks!

Upvotes: 0

Views: 170

Answers (2)

MrTux
MrTux

Reputation: 34003

([^.]+) captures everything until a dot is found.

^\$(\d+\.?\d*) has been received from ([^.]+)\.$

The reason for the backslashes is that the directly following chars a special chars in the regexp language.

When used in Java it would look like this:

"^\\$(\\d+\\.?\\d*) has been received from ([^.]+)\\.$"

The extra backslashes here are needed, because in a Java string backslash itself is a special char and has to be escaped.

Upvotes: 0

Michał Schielmann
Michał Schielmann

Reputation: 1382

According to this site:

http://www.regexplanet.com/advanced/java/index.html

This should work:

^\$(\d+\.?\d*) has been received from (.*).$

Upvotes: 1

Related Questions