Find optional group of characters

Find, replace, find in files, replace in files, regular expressions

Find optional group of characters

Postby newbee72 » Thu Nov 10, 2005 10:43 am

Hi I try to do the following.

I would like to search for as string that looks like

dateFormat or dateTimeFormat

I tried the following, but the grouping of characters doesn't work.

date(Time)*Format

How do i specify to look for such a string.

Regards

Robert
User avatar
newbee72
Newbie
 
Posts: 5
Joined: Thu Nov 10, 2005 12:00 am

Re: Find optional group of characters

Postby Bego » Thu Nov 10, 2005 11:59 am

Hi,

try this:

date[a-zA-Z_]*format

Note: This is a UNIX-regexp style. Probably look for your search setting and change from UE to Unix.

rds Bego :D
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Find optional group of characters

Postby newbee72 » Thu Nov 10, 2005 12:56 pm

Hi ,

thanks for the quick response.
I have tought about that too, but its not quite the same, don't you think so.

i would like the regex to look for a string ( which means a defined order of characters ) and not a abitratry sequenz of allowed characters.

any furhter ideas ?

regards

robert
User avatar
newbee72
Newbie
 
Posts: 5
Joined: Thu Nov 10, 2005 12:00 am

Re: Find optional group of characters

Postby Bego » Thu Nov 10, 2005 1:24 pm

Hmmm, don't really understand.

search for (dateFormat|dateTimeFormat) and you'll get the first 4 of those 5:
dateFormat
dateTimeFormat
dateFormatBlaBla
dateTimeFormatBlaBla
dateIamNotFoundFormat

You need to say at least sth. like this (dateTimeFormat[ \n\r\f]|dateFormat[ \n\r\f])
to eliminate line 3 and 4 too.

Take those extensions to the beginning of the word to also eliminate words like
"myPrefixDateTime"


rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Find optional group of characters

Postby Mofi » Thu Nov 10, 2005 1:30 pm

Yes, use with Unix regular expression (dateFormat|dateTimeFormat) and also check Match Whole Word Only and you should only find "dateFormat" or "dateTimeFormat".
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find optional group of characters

Postby Bego » Thu Nov 10, 2005 1:52 pm

ÖÖÖööh, yes that works too. :idea:
But it's almost TOO easy :wink:

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Find optional group of characters

Postby newbee72 » Thu Nov 10, 2005 3:02 pm

hmm .. thanks ...
so now to the advances section ;-) ....

Actually i want to find the following strings to replace them:

<dateTimeFormat pattern="dd.MM.yyyy" xml:lang="en-us"/>
<dateFormat pattern="dd.MM.yyyy" xml:lang="en-us"/>
<dateTimeFormat pattern="dd.MM.yyyy" />
<dateFormat pattern="dd.MM.yyyy" />

As i have read normally there is a possibility to define groups with (xy) and to add ?, + , * to repeat that phrase in ( ). How is this done in UltraEdit ? Is this part missing in UltraEdit.
User avatar
newbee72
Newbie
 
Posts: 5
Joined: Thu Nov 10, 2005 12:00 am

Re: Find optional group of characters

Postby Mofi » Fri Nov 11, 2005 8:47 am

If you have the replace dialog open, there is a help button. Click on this button and you will get the help. Read it and follow the link to regular expression. Read it carefully, especially but not only the Unix section.

If you do not have success to find the correct expression by yourself, ask again here for help and also add an example how the 4 lines above should look like after the replace.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find optional group of characters

Postby newbee72 » Fri Nov 11, 2005 9:47 am

Hi,

i have read the help and some helps on the internet and didn't have success.
the topic is about a regex, which finds all the above strings. the string konsist of groups which are optional. so normally i would expect a regex like this

<date(time)?format (pattern="[^"]*") (xml:lang="en-us")*\>

But as i mentioned i am missing the opportunity of ()? or ()*. I read that in unix notation this should be possible, but UltraEdit does't recognize the ().
User avatar
newbee72
Newbie
 
Posts: 5
Joined: Thu Nov 10, 2005 12:00 am

Re: Find optional group of characters

Postby Mofi » Fri Nov 11, 2005 10:27 am

You should read about Unix regular expression syntax of ULTRAEDIT and not a general Unix regular expression help!!! What I have wrote above?

UltraEdit's Unix regular expression implementation is not comparable to real Unix regular expression search feature. It is not as powerful as real Unix regular expression. It's just UltraEdit style regular expression with other characters according to Unix style.

The brackets for example are described in the help of UltraEdit as follows:

(expression)
Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.

The corresponding replacement expression is \x, for x in the range 1-9. Example: If (h.*o) (f.*s) matches "hello folks", \2 \1 would replace it with "folks hello".



In real Unix regexp a bracket is used for optional. But in UltraEdit as described it has a total different meaning and does not mean optional.
Now read the help of UltraEdit and think about it.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find optional group of characters

Postby newbee72 » Fri Nov 11, 2005 1:27 pm

Hi ,

thanks , ... i have read that an as i mentioned i did not find an alternative procedure to do something similar with ultraedit.

so my question is, is there a way that i haven't read about, that does the same .

regards

rob
User avatar
newbee72
Newbie
 
Posts: 5
Joined: Thu Nov 10, 2005 12:00 am

Re: Find optional group of characters

Postby Bego » Fri Nov 11, 2005 1:38 pm

Hi rob,

still I don't really know where your problem is ....
put another find/replace example.

Why are you so keen on a string that repeats 0 to several times ?

is there a:
<dateTimeFormat pattern="dd.MM.yyyy" pattern="i dont know" xml:lang="en-us"/>

possible ?
Why does the match described before isn't good enough ?

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Find/Replace/Regular Expressions