How to remove all markers with characters without words in Perl?

I am trying to find a regular expression to remove all words containing characters other than words.

So, if it contains a colon, comma, number, brackets, etc., then remove it from the string, not just the character, but the word. I still have it.

$wordline = s/\s.*\W.*?\s//g;

It’s not necessary to be perfect, so deleting lines with a dash and an apostrophe is fine.

+3
source share
3 answers
s/\w*([^\w\s]|\d)+\w* ?//g;
+2
source
$wordline = join(" ", grep(/^\w+$/, split(/\s+/, $wordline)));
+3
source
s/(?<!\S)(?![A-Za-z]+(?:\s|$))\S+(?!\S)//g

regex-land "-" - , ([A-Za-z0-9_]). , , \w \w . :

  • : \S+

  • does not precede: (?<!\S)or follows: (?!\S)characters without spaces

  • if all characters are not letters: (?![A-Za-z]+(?:\s|$))

This will leave all the spaces surrounding the words that he will delete. Working with them correctly is a little more complicated than you might expect; this is much easier to do in a separate step, for example:

s/^ +| +(?= |$)//g
+2
source

Source: https://habr.com/ru/post/1705877/


All Articles