I'm trying to extract trading pairs from a sentence. A trading pair is two stock tickers plus a /
between them, such as: GME/USD
I'd like write a regexp for browsers (Javascript) that picks up both the GBP and the USD pair.
Here are some sample sentences:
Tomorrow MetaTrade lists the GME/USD and the GME/GBP pairs
Tomorrow MetaTrade lists the TSLA/USD and the TSLA/GBP pairs
I currently have this: (.*)\/USD
but it matches all up to the beginning of the line.
With your shown samples, could you please try following. Online regex demo
\b\w+\/(?:USD|GBP)\b
Complete regex in JS will be:
/\b\w+\/(?:USD|GBP)\b/g
Explanation: Putting a word boundary then looking for \w
(1 or more word characters), which is followed by a non-capturing group of USD
or GBP
keywords followed by a word boundary.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments