Glen Richmond
Glen Richmond

Reputation: 61

Regular expression search term?

Im just looking for a search term in Regular expression that will find all occurrences of measurements in a sentence?

For instance say im looking for Litres (L)?

So there is a number followed by a L or l followed by 1 or many spaces and maybe more text?

So far i have "\d+[l] +" but this doesn't capture all variances like '2L[more than one space]xxxxx'

The end goal is to correct and standardise all text, ie all L's in upper case when in a measurement!

Also i know i could easily use instr() functions but wanted to try RegEx.

Cheers

Upvotes: 1

Views: 60

Answers (2)

Greg
Greg

Reputation: 1116

(\d+)[lL]\s+(.*)

  • Group 1 contains the number of liters (only the number)
  • Group 2 the following text (not sure if this was required)

Matches:

  • 3L foo
  • 2l foo
  • 123213l foo

Ignores:

  • l foo
  • 3lfoo

Upvotes: 1

Riv
Riv

Reputation: 1859

try this: (\d+(\.\d+)?)[lL]\s.+ tested with:

3l Bin works

2L xxx works

2l xxxxx works

2l[just spaces] works

33.33343l works

33 l (no match)

Regex101

Upvotes: 0

Related Questions