josefkoller
josefkoller

Reputation: 11

find for a substring in a string

my problem: I have such a string

B30(XY)=.13-B5(XY) ins A701(XY) and I have to check if there is such a combination in this string (in this example):

.13

This 13 represents a year. So, it is also possible this number combination is .12 or .17 or .01 or .00 ect.

I have no idea how can I check this dot and than two numbers in a given string

Thanks

Josef

Upvotes: 0

Views: 60

Answers (2)

josefkoller
josefkoller

Reputation: 11

Thanks for answers.

But the problem: A year declaration like .133 is also true.

I have to check : .13 is true .133 is false .1 is false

Thanks again.

Josef

Upvotes: 0

epascarello
epascarello

Reputation: 207557

Simple regular expression:

"B30(XY)=.13-B5(XY) ins A701(XY)".match(/\.(\d{2})/)[1]
  • \. - find a "."
  • ( - start of the capture group *\d{2} - followed by two numbers
  • ) - end of the capture group

Upvotes: 6

Related Questions