Regular expression to match trading pair in a sentence

DLeonardi

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.

RavinderSingh13

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular expression to match a sentence

From Dev

Regular expression to match valid words at start, end and in the middle of a sentence

From Dev

Regular expression whole sentence

From Dev

Regular expression matching sentence

From Dev

Regular expression of a sentence

From Dev

Regular Expression for the end of a sentence

From Dev

Python regular expression. Find a sentence in a sentence

From Dev

What could be a regular expression for this sentence?

From Dev

Regular expression in Python sentence extractor

From Dev

how to create regular expression for this sentence?

From Dev

Regular expression for parsing ::number::sentence::

From Dev

Perl regular expression for a repetitive sentence

From Dev

Regular expression in Python sentence extractor

From Dev

"Pair words Extractor" - Regular Expression

From Dev

Regular expression, match between the first, second, third etc. occurences of a pair of words

From Dev

MSVC regular expression match

From Dev

Regular Expression Match - Javascript

From Dev

ruby match regular expression

From Java

Regular expression selectively match

From Dev

Regular expression to match | but not ||

From Dev

Regular Expression Following Match

From Dev

SPARQL regular expression not match

From Dev

Fuzzy match by regular expression

From Dev

Match Regular Expression in Javascript

From Dev

Regular expression to match year?

From Dev

Regular expression for match

From Dev

SPARQL regular expression not match

From Dev

Regular Expression to match scrypt

From Dev

Match with Regular Expression