Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solaris 9 regular expression parser 1

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
Using Solaris 9 and building a Korn shell script with the following statement -

echo $input | sed -e 's/[^[A-Za-z0-9]]//g'


The statement fails to strip any special characters from $input if they are entered.

Changing the range to the POSIX option of :[alnum]: has no affect on the string being parsed correctly either.


The same statement under Red Hat Linux 8 and 9 executes as expected. I am just not sure if I am dealing with a parser issue or a Solaris UNIX issue.


Thanks in advance,

Steve
 
i think I can see the problem. Try this:-

echo $input | sed -e 's/[^A-Za-z0-9]//g'

it looks like you have too many square brackets. the characters following the caret (^) are negated - but you follow the caret with another set of square brackets

let me know how you get on... :)


Kind Regards
Duncan
 
Duncan,


Thanks! That was spot on. However it seems that the parser should have been able to handle the extra brackets based on what the regular expression definitions are.

In any event. I will certainly keep all this in mind as I move forward.


Cheers,

Steve
 
Steve

Thanks for your kind response - and the star!

Cheers dude :)


Kind Regards
Duncan
 
Steve said:
That was spot on. However it seems that the parser should have been able to handle the extra brackets based on what the regular expression definitions are.
The parser handle the first openning '[' after the carret '^'. For the parser, it means you do not want to match '[' no more than A-Z and a-z and 0-9.
But the range of characters ends with the first closing ']'. So you have a (negated) range followed by a ']'.
So it means that you regexp will match a invalid character (not in rang '[A-Za-z0-9') followed by a ']' and replace both (the invalid character and the ']') with nothing.
Just make a try using your first regexp:
Code:
ABC,[de -> ABC[COLOR=red],[[/color]de # invalid char ',' [COLOR=red]not[/color] followed by ']'
ABC[]de -> ABC[COLOR=red][][/color]de # [COLOR=red]valid[/color] char '[' followed by ']'
ABC,]de -> ABCde   # [COLOR=green]invalid[/color] char ',' [COLOR=green]followed[/color] by ']'

--------------------

Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top