How to substring Regular expression in JavaScript

joym8

I have an input which can have up to 50 ASCII characters with a hidden pattern that I need to find. The pattern is the letter A (case insensitive) followed by 8 digits. Only the first pattern (if exists) needs to be found. So an example input can be lkjs#$9234A12345678*)(&kj

How do I do this in JavaScript?

var input = 'lkjs#$9234A12345678*)(&kj';
var regex = '[Aa][0-9]{8}';
var index = input.search(regex);
if (index >= 0) {
    //found pattern - but how to extract it???
}
Denys Séguret

You should use match :

var match = input.match(/a\d{8}/i); // yes, that's an equivalent regular expression
if (match) { // if a match is found
     var str = match[0];
     // here you go, str is your "substring"
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How find substring with regular expression

From Dev

How to replace a substring of a regular expression in text editor

From Dev

Bash substring with regular expression

From Dev

extract substring with regular expression

From Dev

Regular Expression to search substring

From Dev

Regular expression match substring

From Dev

Regular Expression Uninclusive Substring

From Dev

How to develop regular expression in javascript?

From Dev

How to retrieve substring form a string using regular expression in python

From Dev

How can I use Regular Expression to convert String to different substring?

From Dev

How to find a substring from a string using regular expression in php?

From Dev

How to write regular expression to get the substring from the string using regular expression in c#?

From Dev

How to translate java regular expression to javascript regular expression

From Dev

Using a regular expression to extract substring

From Dev

Java regular expression find substring

From Dev

POSIX regular expression to extract a substring

From Dev

Maximize substring match in regular expression

From Dev

perl regular expression match substring

From Dev

Regular expression match multiple substring

From Dev

Regular expression to match URL substring

From Dev

Substring usage in MYSQL with regular expression

From Dev

Python Regular expression to extract a substring

From Dev

a regular expression for substring or exact match

From Dev

Regular expression for a substring from a line

From Dev

Regular expression match multiple substring

From Dev

Remove substring with Ruby regular expression

From Dev

how to create regular expression for folder names in javascript?

From Dev

How to invert an existing regular expression in javascript?

From Dev

How to filter Chinese characters with regular expression in javascript

Related Related

  1. 1

    How find substring with regular expression

  2. 2

    How to replace a substring of a regular expression in text editor

  3. 3

    Bash substring with regular expression

  4. 4

    extract substring with regular expression

  5. 5

    Regular Expression to search substring

  6. 6

    Regular expression match substring

  7. 7

    Regular Expression Uninclusive Substring

  8. 8

    How to develop regular expression in javascript?

  9. 9

    How to retrieve substring form a string using regular expression in python

  10. 10

    How can I use Regular Expression to convert String to different substring?

  11. 11

    How to find a substring from a string using regular expression in php?

  12. 12

    How to write regular expression to get the substring from the string using regular expression in c#?

  13. 13

    How to translate java regular expression to javascript regular expression

  14. 14

    Using a regular expression to extract substring

  15. 15

    Java regular expression find substring

  16. 16

    POSIX regular expression to extract a substring

  17. 17

    Maximize substring match in regular expression

  18. 18

    perl regular expression match substring

  19. 19

    Regular expression match multiple substring

  20. 20

    Regular expression to match URL substring

  21. 21

    Substring usage in MYSQL with regular expression

  22. 22

    Python Regular expression to extract a substring

  23. 23

    a regular expression for substring or exact match

  24. 24

    Regular expression for a substring from a line

  25. 25

    Regular expression match multiple substring

  26. 26

    Remove substring with Ruby regular expression

  27. 27

    how to create regular expression for folder names in javascript?

  28. 28

    How to invert an existing regular expression in javascript?

  29. 29

    How to filter Chinese characters with regular expression in javascript

HotTag

Archive