2

I have written a pseudo code to determine whether the string contains * or not and return the position(start, end, and wrapped) if it contains please check the code sandbox.

The problem is the code works correctly for the string which contains * at the beginning i.e. *string, for other cases it is not working(string* and *string*). Please help me to solve this.

Example strings

console.log(parser.parse("*string"));
console.log(parser.parse("*string*"));
console.log(parser.parse("string*"));
console.log(parser.parse("string"));

Expected output

{star: "start", text: "string"}
{star: "wrapped", text: "string"}
{star: "end", text: "string"}
{star: "no_star", text: "string"}

Code sandbox: https://codesandbox.io/s/javascript-testing-sandbox-forked-5nrj4?file=/src/index.js

Benk I
  • 185
  • 13

1 Answers1

1
TEXT = text:[^* ]+ { return text; }

Solved my issue.

Benk I
  • 185
  • 13