Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Regular expression problem

Reply
Thread Tools

Regular expression problem

 
 
Dan
Guest
Posts: n/a
 
      04-15-2004
I'm trying to remove the word 'AND' (apostrophes included) from a string but
can't seem to get the correct expression.

I've got:

Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
Dim strInput As String = "One 'AND' Two"
Response.Write(regRemove.Replace(strInput, ""))

But it doesn't work. Do the apostrophes in my regex need to be escaped?
I've tried \' and '' but to no avail.

Any ideas?

Thanks


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      04-15-2004

"Dan" <> wrote in message news:%...
> I'm trying to remove the word 'AND' (apostrophes included) from a string but
> can't seem to get the correct expression.
>
> I've got:
>
> Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
> Dim strInput As String = "One 'AND' Two"
> Response.Write(regRemove.Replace(strInput, ""))
>
> But it doesn't work. Do the apostrophes in my regex need to be escaped?
> I've tried \' and '' but to no avail.
>
> Any ideas?
>
> Thanks
>
>


The quote is OK, the problem is with the \b: it matches a boundary
between alphanumeric and non-alphanumeric. Space and ' are both
non-alphenumeric, so there is no boundary!

You could try \B: match on non-boundary.

Hans Kesting



 
Reply With Quote
 
 
 
 
Lars Netzel
Guest
Posts: n/a
 
      04-15-2004
Why not just do this?

NewString = Replace(inputstring, "AND", "")

/Lars



"Dan" <> skrev i meddelandet
news:%...
> I'm trying to remove the word 'AND' (apostrophes included) from a string

but
> can't seem to get the correct expression.
>
> I've got:
>
> Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
> Dim strInput As String = "One 'AND' Two"
> Response.Write(regRemove.Replace(strInput, ""))
>
> But it doesn't work. Do the apostrophes in my regex need to be escaped?
> I've tried \' and '' but to no avail.
>
> Any ideas?
>
> Thanks
>
>



 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      04-15-2004
Thanks, but that won't cope with something like:

SUN AND SAND

"Lars Netzel" <> wrote in message
news:O7x$...
> Why not just do this?
>
> NewString = Replace(inputstring, "AND", "")
>
> /Lars
>
>
>
> "Dan" <> skrev i meddelandet
> news:%...
> > I'm trying to remove the word 'AND' (apostrophes included) from a string

> but
> > can't seem to get the correct expression.
> >
> > I've got:
> >
> > Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
> > Dim strInput As String = "One 'AND' Two"
> > Response.Write(regRemove.Replace(strInput, ""))
> >
> > But it doesn't work. Do the apostrophes in my regex need to be escaped?
> > I've tried \' and '' but to no avail.
> >
> > Any ideas?
> >
> > Thanks
> >
> >

>
>



 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      04-15-2004
Great, thanks! This did the trick.

"Hans Kesting" <> wrote in message
news:...
>
> "Dan" <> wrote in message

news:%...
> > I'm trying to remove the word 'AND' (apostrophes included) from a string

but
> > can't seem to get the correct expression.
> >
> > I've got:
> >
> > Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
> > Dim strInput As String = "One 'AND' Two"
> > Response.Write(regRemove.Replace(strInput, ""))
> >
> > But it doesn't work. Do the apostrophes in my regex need to be escaped?
> > I've tried \' and '' but to no avail.
> >
> > Any ideas?
> >
> > Thanks
> >
> >

>
> The quote is OK, the problem is with the \b: it matches a boundary
> between alphanumeric and non-alphanumeric. Space and ' are both
> non-alphenumeric, so there is no boundary!
>
> You could try \B: match on non-boundary.
>
> Hans Kesting
>
>
>



 
Reply With Quote
 
Lars Netzel
Guest
Posts: n/a
 
      04-15-2004
true!

Can you use a comma instead of AND to separate the words in the string and
just split everything into an array?

/Lars

"Dan" <> skrev i meddelandet
news:%...
> Thanks, but that won't cope with something like:
>
> SUN AND SAND
>
> "Lars Netzel" <> wrote in message
> news:O7x$...
> > Why not just do this?
> >
> > NewString = Replace(inputstring, "AND", "")
> >
> > /Lars
> >
> >
> >
> > "Dan" <> skrev i meddelandet
> > news:%...
> > > I'm trying to remove the word 'AND' (apostrophes included) from a

string
> > but
> > > can't seem to get the correct expression.
> > >
> > > I've got:
> > >
> > > Dim regRemove As New System.Text.RegularExpressions.Regex("\b'AND'\b")
> > > Dim strInput As String = "One 'AND' Two"
> > > Response.Write(regRemove.Replace(strInput, ""))
> > >
> > > But it doesn't work. Do the apostrophes in my regex need to be

escaped?
> > > I've tried \' and '' but to no avail.
> > >
> > > Any ideas?
> > >
> > > Thanks
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57