Search A SubString Between Two Points Of A String Dynamically

Awais Umar

How can we search and save substring inside a string between two specified values dynamically. For example if a have the following set of strings.

var string1 = "This is.. my ..new string";
var string2 = "This is.. your ..new string";

Now what to do if i want to save the subsrting that is between two dots, "my" and "your" in this case, from the string, maybe in another variable or maybe by removing everything except "my". I know it can be possible using indexof("my") but that would not be dynamic.

TwilightSun

Regular Expression is THE solution for this kind of problems. You can do some google on it. There's lots of documents and tutorials out there.

For your particular question, to get the string in between "..", you can use the following code

var match1 = string1.match('\\.\\.\\s*(.+?)\\s*\\.\\.');
match1 = match1 ? match1[1] : false;
var match2 = string2.match('\\.\\.\\s*(.+?)\\s*\\.\\.');
match2 = match2 ? match2[1] : false;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

ORACLE SQL replacing the substring dynamically in a big string based on another substring

分類Dev

Check if a Point is between two Points

分類Dev

Variable length substring between two characters

分類Dev

Elastic Search substring search

分類Dev

How can I find the nth substring in between two substrings in C?

分類Dev

Optimizing finding matching substring between the two lists by regex in Python

分類Dev

php substring occurances between two strings in an html file

分類Dev

php substring occurances between two strings in an html file

分類Dev

Search documents between two dates in a view with a NotesViewNavigator

分類Dev

Cut a string between two lines

分類Dev

How can calculate the real distance between two points with GeoDjango?

分類Dev

Visualizing the difference between two points with ggplot2

分類Dev

Draw line between two given points (OpenCV, Python)

分類Dev

Line between two draggable points on a matplotlib pyqt5 canvas

分類Dev

How to check if between two points in time C#

分類Dev

Calculate distance between two lat long points in Oracle

分類Dev

How to draw image dynamically on a canvas line between two cells

分類Dev

Java: Splitting a String at two different points into 3 parts

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

How to get the string between two dots in bash?

分類Dev

Python Regex Get String Between Two Substrings

分類Dev

How to get String between last two underscore

分類Dev

How to extract a string between two characters?

分類Dev

removing string between two words in unix

分類Dev

Error getting the string between two patterns

分類Dev

regex to ignore a character in between two string?

Related 関連記事

  1. 1

    ORACLE SQL replacing the substring dynamically in a big string based on another substring

  2. 2

    Check if a Point is between two Points

  3. 3

    Variable length substring between two characters

  4. 4

    Elastic Search substring search

  5. 5

    How can I find the nth substring in between two substrings in C?

  6. 6

    Optimizing finding matching substring between the two lists by regex in Python

  7. 7

    php substring occurances between two strings in an html file

  8. 8

    php substring occurances between two strings in an html file

  9. 9

    Search documents between two dates in a view with a NotesViewNavigator

  10. 10

    Cut a string between two lines

  11. 11

    How can calculate the real distance between two points with GeoDjango?

  12. 12

    Visualizing the difference between two points with ggplot2

  13. 13

    Draw line between two given points (OpenCV, Python)

  14. 14

    Line between two draggable points on a matplotlib pyqt5 canvas

  15. 15

    How to check if between two points in time C#

  16. 16

    Calculate distance between two lat long points in Oracle

  17. 17

    How to draw image dynamically on a canvas line between two cells

  18. 18

    Java: Splitting a String at two different points into 3 parts

  19. 19

    Extracting a string between other two strings in R

  20. 20

    Extracting a string between other two strings in R

  21. 21

    Extracting a string between other two strings in R

  22. 22

    Extracting a string between other two strings in R

  23. 23

    How to get the string between two dots in bash?

  24. 24

    Python Regex Get String Between Two Substrings

  25. 25

    How to get String between last two underscore

  26. 26

    How to extract a string between two characters?

  27. 27

    removing string between two words in unix

  28. 28

    Error getting the string between two patterns

  29. 29

    regex to ignore a character in between two string?

ホットタグ

アーカイブ