genuinebasil
genuinebasil

Reputation: 103

Using Regular Expression to extract value

Could someone please help me with this scenario,

[Some text]

[Some text] Device ID: XYZ123 [Some text]

[Some tex]

I want to extract XYZ123 from the above sample. Appreciate your help.

Upvotes: 0

Views: 107

Answers (2)

Regexident
Regexident

Reputation: 29552

You can use:

(?<=Device ID: )\b[a-Z0-9]+\b

(get ID via catch group #0)

Assuming your regex engine supports lookbehinds, otherwise use:

Device ID: (\b[a-Z0-9]+\b)

(get ID via catch group #1)

Note: I herein assume that the [ and ] are not actually found in your source text, are they?

Upvotes: 1

fardjad
fardjad

Reputation: 20394

try this:

\[[^\]]+]\s*Device ID\:\s*(?<DeviceID>[A-Z0-9]+)\s*\[[^\[]+\]

Upvotes: 0

Related Questions