0

I'm not very familiar with english and still less with javascript, sorry for that.

I have lots of extracted datas in a field named LT, I need to extract a particular data from LT field in javascript, this data is a number after "Relevé N° :" or sometimes after "N° de relevé :" expression is never exactly the same.

I actually use that: record.fields.LT.substring(record.fields.LT.indexOf("relev")).slice(10, 19);

But that dont match because sometimes there is more than one space or the "R" is uppercase etc..

Some help would be appreciated ;-)

Thanks Bryan

EDIT: thank you both for your answers, here is some screenshots for a better understanding 1

I try first suggestion and it ask for missing ; and ) but when i add it, nothing remain in field as you can see on picture2 2

and when i try second answer, there is a syntax problem(seems to be the "(?:")

2
  • Is pulling the last number from the string sufficient? You should show some examples indicating possible values. Commented Jul 4, 2017 at 16:25
  • Extracted data in LT could be for example: "laboratoire trucmuch 11, rue de la pine CS 51086 ID : 467466 telephone : 03 26 89 55 22 Relevé N° : 12345678 blabla bla bla" I need the number 12345678 after "Relevé N° :" this number always composed from 7 or 8 digits Commented Jul 4, 2017 at 16:31

2 Answers 2

1

If the pattern you are looking for is only either 'Relevé N° :' or 'N° de relevé :' case insentitive, you can use a regex to capture the number that follows.

var testStrings = [
      "abc Relevé N° :12345678 string1",
      "123Relevé N° :1234567 string2",
      "aRelevé N° :1234567 string3",
      "N° de relevé :12345678 string4",
      "abc N° de relevé :12345678 string5"
    ];
    var myRegexp = /(Relevé N° :|N° de relevé :)([0-9]{7,8})/i;
    testStrings.forEach(function(str) {
      var match = myRegexp.exec(str)
      console.log(str + '   -> ' + match[2])
    })

Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure what you are asking for, but as per my understanding, the following regex should help.

 (?:((Relevé N° : )|(N° de relevé : )))[0-9]{7,8}

This uses a non-capturing group (not available in all regex implementations.) It will say, hey the String better have phrase like Relevé N° : or N° de relevé :, but I don't want this phrase to be part of my match, just the numbers (which is of length of 7 or 8) that follow.


Hope this helps! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.