Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesHi, This is not SQL Server database problem, however, net search has failed to generate a solution to the problem, I'm trying my luck at this NG now. Problem, remove the special character, [ from text. e.g. text = "this is [1] and [stuff] and some [2] and hat [3] and dog" Desired result = "this is 1 and [stuff] and some 2 and hat 3 and dog" I know [[:digit:]] would find all the instances of digits inside brackets such as [1], [2], [3]. However, I don't know how to ge t rid of the special characters of [ and ]. Any regular expression expert out there? Thanks. Don
Post Follow-up to this messageNickName (dadada@rock.com) writes: > This is not SQL Server database problem, however, net search has failed > to generate a solution to the problem, I'm trying my luck at this NG > now. > > Problem, remove the special character, [ from text. > e.g. text = > "this is [1] and [stuff] and some [2] and hat [3] and dog" > > Desired result = > "this is 1 and [stuff] and some 2 and hat 3 and dog" > > I know [[:digit:]] would find all the instances of digits inside > brackets such as [1], [2], [3]. However, I don't know how to get rid > of the special characters of [ and ]. > > Any regular expression expert out there? Since you did not specify which regular expressions you are using, I'm taking the liberty to answer with the regexps I know, that is those of Perl. In Perl you would say: s/\[([0-9]+)\]/\1/g The \[ means [, that is \ is an escape charactter. () is for groupin g, and \1 refers back to this paren. I have only seen glimpses of the regexps in .Net, but it appears to be similar to Perl. There might be different rules for when you need \ though. In Textpad that I use, I would have to say \( and \)to use parens for grouping. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techin.../2000/books.asp
Post Follow-up to this message> Problem, remove the special character, [ from text. > e.g. text = > "this is [1] and [stuff] and some [2] and hat [3] and dog" > > Desired result = > "this is 1 and [stuff] and some 2 and hat 3 and dog" Using the Zeus editor: http://www.zeusedit.com These are the search and replace regular expresions: Search: (\[)([0-9]+)(\]) Replace: \2 Note: Zeus is shareware (45 day trial). Jussi Jumppanen Author: Zeus for Windows
Post Follow-up to this messageErland, I appreciate your response, unfortunately I'm not using Perl. Don
Post Follow-up to this messageJussi, Thanks for the response, I think your tool seems clever, and yet I'm trying not to introduce many tools within one project. Don.
Post Follow-up to this messageNickName (dadada@rock.com) writes: > I appreciate your response, unfortunately I'm not using Perl. If in you insist on not telling what you use, the responses may not always be applicable. Anyway, I hoped that you would be able to translate the Perl stuff to whatever you are using. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techin.../2000/books.asp
Post Follow-up to this messageNickName wrote: > Thanks for the response, I think your tool seems clever, and > yet I'm trying not to introduce many tools within one project. The good thing is the regexp's that I posted are just standard unix style regexp's so they should work with any tool that can handle these type of regexp's. Jussi Jumppanen Author: Zeus for Windows http://www.zeusedit.com
Post Follow-up to this messageShoot, you're tricky, now that you say it's sort of generic, I tried it and it works nice, thanks.
Post Follow-up to this messageErland, Jussi's solution solved the problem. You seem a very kind person, if one day I travel to Sweden and you're available, I would love to buy you a beer. Kind regards, Don Li
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread