user1879573
user1879573

Reputation: 251

Regular Expression to match alphanumeric, non alphanumeric and spaces

I want to match strings containing alphanumeric, non alphanumeric characters (simple punctuation marks including underscores, hyphens and decimal points) and spaces in my input file and then print them to a separate file.

Here's an example of the string:

ID123 MIR24-2 10.6

I can search for individual items in the string but nothing that ties the whole lot together including the spaces.

I've tried:

/^[a-zA-Z0-9]*[A-Za-z0-9_-]*[-0-9.0-9]*$/

Upvotes: 0

Views: 201

Answers (3)

Toto
Toto

Reputation: 91498

Not sure I understand well your needs, but is this regex work for you?

$str =~  /\w+\s[\w-]+\s\d+\.\d+/;

Upvotes: 1

Pradeep
Pradeep

Reputation: 3153

Try regex something like this /^[\w+\d\s-]+$/i. Are there any patterns like it'll contain at least 1 space etc.?

Upvotes: 0

Johann Blais
Johann Blais

Reputation: 9469

Try something like that ^[A-Za-z\d\s-]*$

Upvotes: 0

Related Questions