473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regex syntax

!NoItAll
297 100+
I'm trying to remove the following from a string
Any occurance of

<br> </br> <br clear="all"> <br/> <br />

Here's my string

<br></br><br clear="all">Hello bright girl<br/><br /></br>

I am trying the .net regex like this

Expand|Select|Wrap|Line Numbers
  1. sLine = System.Text.RegularExpressions.Regex.Replace(sLine, "<\/?br.*>", String.Empty, RegularExpressions.RegexOptions.IgnoreCase)
and it just doesn't work the way I think it should! I wind up with the following string: <b><h1>
and that's it!
What is wrong with my syntax?

Here's my thinking
< is the literal
\/? escapes the / so I am looking for 0 or 1 / (forward slash)
br is a literal string because I'm looking for "br"
.* I am looking for 0 to many of any character
> the closing literal

I've tried all kinds of combinations - and get close...

The following pattern works pretty well: "<\/?br\W*>"

I get the following string:
<b><h1><br clear="all">Hello bright girl</h1></b>

For some reason, however, it misses the <br clear="all">
Nov 14 '09 #1

✓ answered by Markus

Apply the same logic for your leading forward slash, that is, make the " clear='all'" optional.

Regex: <\/?br.*?>

3 2043
Markus
6,050 Expert 4TB
Apply the same logic for your leading forward slash, that is, make the " clear='all'" optional.

Regex: <\/?br.*?>
Nov 15 '09 #2
!NoItAll
297 100+
Superb - thank you. I did not think you could "stack" * and ? together to accomplish this.
I did find a site that helps a lot. It's a pretty elegant regex text application!

http://www.gskinner.com/RegExr/

It helps because you can just play with it until you get something to work...
Nov 15 '09 #3
Markus
6,050 Expert 4TB
Glad I could be of help.

I prefer the desktop solutions for regex testing - there's also a good plugin for firefox :)
Nov 15 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: zOrg | last post by:
hi, i'm using the preg_match_all() function to parse an asp file and find all include file within this file : asp include strings can be : <!--#include virtual="/dir/file.asp"--> or...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
3
by: Stephan Bour | last post by:
I have a string ³Name² in the following format: ³LastName, FirstName (Department)² that comes from Active Directory. I need to extract the FirstName from the string. Substrings are not practical...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
5
by: lgbjr | last post by:
Hello All, I have the following type of string: "X:Y\Z.exe" "123" What I need is an array of strings with the information from within each set of quotes. I was trying to use a Regex.Split, but...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
3
by: gisleyt | last post by:
I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'(*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File...
8
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what...
2
by: rockstar_ | last post by:
Hello all- I'm developing a Content Management software for my own site, and possibly package and deploy to other sites (for friends, family, etc.) The content management software is combined...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.