0

I have the string:

"Vl.55.16b25.3d.42b50.59b30.90.24b35.3d.56.67b70.Tv.54b30.Vl.41b35.Tv.Bd.71b50.3d.99b20.03b50.Tv.73b50.Vl.05b25.12b40.Bd.Tv.82b25."

How to detached get results like:

["Vl.55.16b25", 3d.42.b50.59b30.90.24b35, 3d.56.67b70, ...]

The logic:

Condition 1: The End will be start b and 2 number. Example: b20, b25. If pass condition 1 I need to check condition 2.

Condition 2: maybe like "3d" or 2 characters. If don't match condition 2 we need to pass the next character to the current block.

Many thanks.

2
  • 1
    meta.stackoverflow.com/questions/284236/… Commented Apr 9, 2022 at 8:53
  • 1
    I did my best to improve the readability but this question is very unclear. You should be more clear about what kind of conditions you expect the logic to implement to return such a parsing from the input string Commented Apr 9, 2022 at 9:00

2 Answers 2

1

If I understand your question correctly, the following code should work:

var string = "Vl.55.16b25.3d.42b50.59b30.90.24b35.3d.56.67b70.Tv.54b30.Vl.41b35.Tv.Bd.71b50.3d.99b20.03b50.Tv.73b50.Vl.05b25.12b40.Bd.Tv.82b25.";
console.log(string.split(/(?<=b\d\d)\.(?=3d)/g))

Explanation:

  • (?<=) is look-behind.
  • b matches the literal character "b".
  • \d matches any digit so \d\d will match two digits in a row.
  • \. matches a literal ".", it needs the \ before it because otherwise it would match any character.
  • (?=) is look-ahead.
  • The g flag stands for global so the string will be split up at every occurrence of the regular expression.

This means that the string will be split at every occurrence of "." that is preceded the letter "b" then two digits, and followed by "3d".

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

1 Comment

That worked for me, but I think missing (Condition 2 maybe like "3d" or 2 characters) :). Thanks for your help.
0

Assuming you want to separate by last having 'b' and two digits followed by 3d, two digits or the end of string (this is necessary) and by omitting leading dot, you could take the following regular expression.

const
    string = "Vl.55.16b25.3d.42b50.59b30.90.24b35.3d.56.67b70.Tv.54b30.Vl.41b35.Tv.Bd.71b50.3d.99b20.03b50.Tv.73b50.Vl.05b25.12b40.Bd.Tv.82b25.",
    result = string.match(/[^.].*?b\d\d(?=\.(3d|\D\D|$))/g);

console.log(result);

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.