1

I have some text, I need to select only alphanumeric characters only in single match.

I have tried this in regex

[^\W]+

Pattern : [^\W]+

Input:  This is "My Page"

https://rubular.com/r/PMQwahJIqqiOOI

Output I Need: This is My Page

Rubber
  • 87
  • 9
  • Join the result with a single space? This will avoid the capture of multiple space – xdtTransform May 06 '19 at 07:51
  • The only way is to remove the non-alphanumeric characters. Or concatenate the sub-matches. – montonero May 06 '19 at 07:51
  • BTW, concatenating matches is preferable if spaces should not be preserved and you want to get alphanumeric substrings separated with a single space: it is much cleaner with a mere `\w+` regex. See [this thread on how to get multiple matches](https://stackoverflow.com/questions/4892452). – Wiktor Stribiżew May 06 '19 at 08:29

1 Answers1

2

Remove everything that is not word character or space using this regex,

[^\w ]+

with empty space.

Regex Demo

Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36