New here, trying to learn regex -
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
New here, trying to learn regex -
I've read thru help and some tutorials but still struggling.
I am just testing different expressions, but sometimes I
cant see why they don't work. I'm just going to start asking
When I use this regex
^[a-z]*
I expected to find the start of a line and the first portion of that line containing letters a-z.
Instead I get nothing. Does the * not work after the []?
Bill
I am just testing different expressions, but sometimes I
cant see why they don't work. I'm just going to start asking
When I use this regex
^[a-z]*
I expected to find the start of a line and the first portion of that line containing letters a-z.
Instead I get nothing. Does the * not work after the []?
Bill
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Does it work when you put a check mark in the box for "Regular expression" ?
Make sure there is no checkmark in "Match case" ?
If that does not work, then:
Are you getting back an error message? What does it say?
Provide a sample of the text you are searching.
Make sure there is no checkmark in "Match case" ?
If that does not work, then:
Are you getting back an error message? What does it say?
Provide a sample of the text you are searching.
Hope this was helpful.............good luck,
Bob
Bob
This seems like a bug to me. The expression work fine on my computer as long as i start the search when the cursor is on the beginning of a line that start with a letter. When i start the search or click find next when the cursor is on the beginning of a line that do not start with a letter or is empty it won't continue to search the rest of the lines below even if they match it seems.
For example using this lines:
When the cursor is at the beginning of line 2 or in the middle of line 1 when i search using the expression ^[a-z]+ i get a match on "aa", but if the cursor is on the beginning of line 1 when i start the search i get no match, error or messages......basically nothing happen when i click the find button. Seems like textpad behave a bit strange compared to other text editors using regular expression with the "*".
Anyway wjb i believe the the expression you really want to use in this case to get the result you want is a "+" instead of a "*" (Like this: "^[a-z]+").
For example using this lines:
Code: Select all
5555
aa22
Anyway wjb i believe the the expression you really want to use in this case to get the result you want is a "+" instead of a "*" (Like this: "^[a-z]+").
That regular expression should match every single line in any file (unless match case is checked) since all it says is "match the lines that begin with zero or more occurences of any (lowercase) letter". If a line begins with a lowercase letter the regex matches (1 occurrence), if it doesn't the regex will match anyway (0 occurrences).
What's strange is that it wont match any more lines after matching one not beginning with a letter (tested with 5.03). OTOH clicking "mark all" correctly marks every line...
What's strange is that it wont match any more lines after matching one not beginning with a letter (tested with 5.03). OTOH clicking "mark all" correctly marks every line...
Once it has matched the nothingness at the beginning of the first line, it starts for matching the next thing immediately after the first match - i.e. at the beginning of the first line.agnul wrote:What's strange is that it wont match any more lines after matching one not beginning with a letter (tested with 5.03). OTOH clicking "mark all" correctly marks every line...
There the condition that the match must start at the beginning of the line is still true, and the beginning of the line is still followed by nothing (or more).
Therefore the second match happens at exactly the same place as the first one.
And the third, fourth, fivth, ... also.
For the Mark All, Textpad probably marks the line of the first hit and starts at the next line as for marking all matching lines it does not matter if there is just one or infinitely many matches in this line - once the line matches and gets marked it is no longer of interest.
As far as i understand searching for "^[a-z]*" would be a wrong way of using the regular expressions anyway since it will match every line. I cannot see how that could be useful, but still "find next" shouldn't find the same occurrence without moving to the next.
I use another text editor as well and seems to work as expected using that editor so "find next" find the next occurrence and not the same over and over again. Not a big deal though since searching for "^[a-z]*" isn't really useful.
I use another text editor as well and seems to work as expected using that editor so "find next" find the next occurrence and not the same over and over again. Not a big deal though since searching for "^[a-z]*" isn't really useful.
It should match every line, TP however stops when it hits an empty line, or a line that doesn't start with a-z.
I tried some other editors:
NP++ shows the same behaviour as TP
VS2003/2005/2008 find every line
NetBeans highlights every line starting with a-z
I tried some other editors:
NP++ shows the same behaviour as TP
VS2003/2005/2008 find every line
NetBeans highlights every line starting with a-z
gan wrote:As far as i understand searching for "^[a-z]*" would be a wrong way of using the regular expressions anyway since it will match every line.
Because [a-z]+ matches at least one character.wjb wrote: Don't know why using the ^[a-z]+ gets by a blank line but ^[a-z]* does not.
Thus after each match, the start position for the search of the next match is at a different position. Thus no endless loop of matching at the same position can occur.