How to select this piece of text in Regex

3

I have the following sample text:

1.1.1.1.1. Test. Test1.

1.1.1.1. Test

1. Test

I would like to select the 1. of all but the test. I used the following regex: ([0-9].) The problem is that on the first line it selects 1. in Test1. and I would like you to select the first letter. Could you help me with that?

Thank you in advance!

EDIT 1:

Selecting everything in front of the last 1. also helps. These numbers are the levels of a tree and I would like to remove them only by keeping the rest of the text

    
asked by anonymous 21.06.2017 / 21:31

3 answers

4

Dude, go through the lines and apply:

^\s*[0-9\.]*\s*

This regex removes what you intend ... just that it has to be run row by line, with a FOR or a WHILE and giving a replace of the value found by ''.

If you prefer, you can use the regex below and substitute a line break (\ n):

(^|\n)\s*[0-9\.]*\s*
    
21.06.2017 / 21:54
4

If I understand correctly you want to filter some of the content and want to replace it.

So even if there is something else you want it will always be something like:

  

1.1.1.1.1. Test.
   1.1. Test.
   1. Testing.

You have also commented on the tree, in this case there may be other indexes such as:

  

1.43.7.112. Test.
   26.0.177. Test.

But you want to remove the indexes by keeping only the text.

Result

pattern : /(\d+\.)+ (\w)/g
replace : $2

Explanation

  • (\d+\.)+ - This part takes care of the indexes, as it is a group with + , it repeats the possibility of the group the maximum that achieves, being at least 1.
  • - Literal space (I believe that after the index you have a spacing)
  • (\w) - Group 2, REGEX limit to know when the text started.

replace replaces everything that was captured.

  • $2 - replaces the entire sentence with the character captured in group 2.

See working at REGEX101 .

    
22.06.2017 / 14:09
3

I recommend doing regular expressions, gradually, in parts. Look how I've built a expression to validate emails .

Come on, catching the most general:

.*

Here we get everything married, so let's filter. It is necessary to pick up from the beginning, so we can put the anchor ^ logo:

^.*

Hmmm, you also said that you want everything until you get the first letter ... so we can marry anything but letters, what's up? Let's use the denied list for this:

^[^A-Za-z]*

Well, let's just make sure it goes up to a letter? Let's use the list for this, and we can also group for a possible text replacement in the future:

 ^([^A-Za-z]*)[A-Za-z]

Ok, now we have the desired text in the grouping recognized by the mirror = D

  

More about regex see the Aurélio Verde's Quick Guide to Regular Expressions .

    
21.06.2017 / 23:55