Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 30th, 2012, 01:47 PM
armagaddon armagaddon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 armagaddon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 14 sec
Reputation Power: 0
Regex doesnt work on img tags in Html

Hey Guys,

I'm an absolute beginner with regular expressions, but need some help with my expression.

I'm having a java string:

"TAG'G' CLTG TAG hello CLTG"

and my expression to remove everything between the tags "TAG" and "CLTG":

TAG[^CLTG]*CLTG

If I test the regex on my string, and replace it with nothing (string.replaceAll(regex, "") , It works only with the second Tag, but not with the first TAG.

This is no logical connection for me, why the first one works and the second one doesnt .
Maybe you can help me?

greetz arma

Reply With Quote
  #2  
Old March 30th, 2012, 03:51 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Hi armaggadon,

Welcome to the DevShed regex board.
You bring a fantastic beginner question.
Here are some elements to help you understand what is going wrong.

1. [^CLTG] does not mean "not CLTG", but "any ONE character that is not a C, a L, a T or a G".

2. You probably have case-insensitive mode on? If so, on the second tag (TAG hello CLTG), the regex will fail on the first "l" in hello, as it is trying to match any one character that is not a L (or a c, t, or g).

3. Here is a way to match your entire tag:
Code:
TAG(?:[^C]|C(?!LTG))*CLTG

It matches TAG, then
any character that is NOT a C, OR a C that is not followed by LTG,
zero or more times,
then CLTG.

The (?! is a negative lookahead from regex lookaround syntax.

You probably know that by adding parentheses, you could "capture" the text between TAG and CLTG, if for whatever reason you needed it later in your code or replacement.

Hope this helps, let me know if you have any questions!
Wishing you a fun weekend.

__________________
Regex Tutorial | Latest RegexBuddy Demo

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Regex doesnt work on img tags in Html

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap