Regex - Expression to paste limited fields

2

I have the following string:

"Let's put some bits in your home"

Using regular expression, how could I just get information from bits forward, getting:

bits in your home

That is, the other words are discarded.

Has anyone seen any such cases?

    
asked by anonymous 15.05.2018 / 21:10

2 answers

1

It depends a lot on the variations that the String of entry can have, and which characters you want to get.

The simplest case is:

(bits.*)

What gets bits + everything you have afterwards.

Only .* means "zero or more occurrences of any character".

If you do not want some character types, or just want certain types (like letters, numbers, or spaces), or any other rule, you can restrict more by using something like Israel's response .

For example:

(bits[a-zA-Z0-9 ]*)

[a-zA-Z0-9 ]* will get only letters, numbers, or space (zero or more occurrences of any of these characters). Change the expression according to what you need.

Depending on the regex engine and / or the language / API you use, . may or may not consider line breaks ( \n and \r ). Some APIs allow you to even configure this ( example ). I do not know if this applies to your case (since it was not specified), but it's a point of attention.

    
15.05.2018 / 21:18
1

If you want to always get past the word 'bits', you can use this simple expression:

(bits[^\n]*)

It captures everything after (and including) the word 'bits' until it finds a line break.

See this example working

    
15.05.2018 / 21:14