AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Put here requests of problems with regular expressions
Goto page Previous  1, 2, 3 ... 17, 18, 19
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Krogdor



Joined: 18 Apr 2008
Posts: 1090
Location: The Interwebs

PostPosted: Mon Jul 28, 2008 2:44 am    Post subject: Reply with quote

Hm. Try:
Code:
output := RegExReplace(sgml, innerTag . "=""\d+""(?:\s|(/))","$1")
Back to top
View user's profile Send private message AIM Address
UIO1
Guest





PostPosted: Mon Jul 28, 2008 3:13 am    Post subject: Reply with quote

Ah, poifect. Thank you so very much & also to Guest of Honor for other help on different problem. I think this shores me up, and is very efficient and good. have fantastic week ahead....
Back to top
keybored



Joined: 18 Jun 2006
Posts: 101
Location: Phoenix, AZ

PostPosted: Tue Nov 18, 2008 1:30 am    Post subject: Anchors and line characters Reply with quote

I'm having particular trouble with understanding anchors. The file I'm trying to get data has headers for every page and I'm hoping to remove them all with one regexreplace.
I've tried just the ----$, but that fails. Any help is appreciated.

Code:
v_Data =
(
Keep This 1
00/00/00 AAA


00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep That 1

Keep This 2
00/00/00 AAA


00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep That 2
)

v_Result := RegExReplace(v_Data, "^\d\d/\d\d/\d\d.*$", "")

msgbox, %v_Result%

[/code]
Back to top
View user's profile Send private message
tonights guest
Guest





PostPosted: Tue Nov 18, 2008 10:12 am    Post subject: Re: Anchors and line characters Reply with quote

keybored wrote:
I'm having particular trouble with understanding anchors. The file I'm trying to get data has headers for every page and I'm hoping to remove them all with one regexreplace.
I've tried just the ----$, but that fails. Any help is appreciated.
Assuming I understand you, you want to remove all lines of the form 00/00/00 AAA (along with the newline it contains), the regex used here works: (copy/past/run this tested code to see the result).
Code:
#SingleInstance, force

v_Data =
( %  ; <---------- % option to treat "%" as literal
Keep This 1
00/00/00 AAA


%0C00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep That 1

Keep This 2
00/00/00 AAA


%0C00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep That 2
)

v_Result := RegExReplace(v_Data,"m`n)^\d\d/\d\d/\d\d.*\n$","")
separator = `n===============================================================`n
msgbox, % separator "v_Data" separator V_Data separator "v_Result" separator v_Result
ExitApp

Notice the regex options "m" and "`n"
RegExMatch 'm' option wrote:
Multiline. Views haystack as a collection of individual lines (if it contains newlines) rather than as a single continuous line. Specifically, it changes the following:

1) Circumflex (^) matches immediately after all internal newlines -- as well as at the start of haystack where it always matches (but it does not match after a newline at the very end of haystack).

2) Dollar-sign ($) matches before any newlines in haystack (as well as at the very end where it always matches).

For example, the pattern "m)^abc$" matches the haystack "xyz`r`nabc" solely due to the "m" option.
And, using the v_Data continuation in your code, produces lines that are separated by a solitary newline (`n) character.
RegExMatch option '`n' wrote:
Switches from the default newline character (`r`n) to a solitary linefeed (`n), which is the standard on UNIX systems. The chosen newline character affects the behavior of anchors (^ and $) and the dot/period pattern.
Back to top
keybored



Joined: 18 Jun 2006
Posts: 101
Location: Phoenix, AZ

PostPosted: Tue Nov 18, 2008 3:04 pm    Post subject: oops Reply with quote

I actually want to remove several lines of headers. I guess I was confusing things with my labels of keep this keep that. I want to keep anything with ...

This \s\d\d/\d\d/\d\d.*---\s seems to remove more than one line, but is also taking the middle part.

Code:
v_Data =
(
...Keep 1
00/00/00 AAA


00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep 2
...
Keep 3
00/00/00 AAA


00/00/00            A A A   A A A A A A A A   A A A A A A              AAAA: 0

  AAAA     AAAA       AAAAAA          AAAAAAAAAAA         AAAAAAA:      0000
-------- -------- -----------------------------------------------------------
Keep 4...
)

v_Result := RegExReplace(v_Data, "\s\d\d/\d\d/\d\d.*---\s", "")

msgbox, %v_Result%



Edited:
The results I'm trying to achieve would keep the lines above and below these annoying headers. I really only copied the headers from work having focused on avoiding disclosing confidential information than I did actually what would be needed.


This is what I want to keep;
Code:
...Keep 1
Keep 2
...
Keep 3
Keep 4...


And this is what I want to remove;
Code:

00/00/00            A a a   A a a a a a a a   A a a a a a              Aaaa: 0

  Aaaa     Aaaa       Aaaaaa          Aaaaaaaaaaa         Aaaaaaa:      0000


Last edited by keybored on Tue Nov 18, 2008 5:23 pm; edited 2 times in total
Back to top
View user's profile Send private message
tonights guest
Guest





PostPosted: Tue Nov 18, 2008 3:15 pm    Post subject: Re: oops Reply with quote

keybored wrote:
I actually want to remove several lines of headers. I guess I was confusing things with my labels of keep this keep that. I want to keep anything with ...

This \s\d\d/\d\d/\d\d.*---\s seems to remove more than one line, but is also taking the middle part.

That is less clear than your first post. Crying or Very sad
Given the v_Data you have posted, please post exactly the text you want removed from each record (or if you prefer, post the desired result to be in v_Result), and I will see if I can help.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3 ... 17, 18, 19
Page 19 of 19

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group