Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to insert \s into charIn? #526

Unanswered
cdwmhcc asked this question in Q&A
Discussion options

About \s

  1. charIn('-\\s') => [\-\\s]
  2. charIn('-\s') => [\-s]
  3. charIn('-${whitespace}') => [\-\\s]

How to solve this problem?

/0|[1-9]\d*/

Also, is there a more concise way to write it?:

after(anyOf(charIn(`-_ `), exactly('').at.lineStart()))

Thank you!

You must be logged in to vote

Replies: 2 comments

Comment options

Temporary solution:

export function charIn(chars: string | RegExp): Input {
 if (chars instanceof RegExp) return createInput(chars.source)
 return createInput(`[${chars.replace(/[-\\^\]]/g, '\\$&')}]`)
}
const positiveInteger = charIn(/[1-9]/).and(digit.times.any())
const commonSeparator = charIn(/[-_\s.]/)
const boundary = charIn(/[-_\s()\/:]/)
const lookbehind = createInput(`(?<=^|${BOUNDARY})`)
const lookahead = createInput(`(?=${BOUNDARY}|$)`)
You must be logged in to vote
0 replies
Comment options

0.9.0 added:
charIn.from('1', '9')

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /