Jump to content
Sign in to follow this  
myname1

Removing text from lines automatically? (RegExp?)

Recommended Posts

myname1

How to remove the bolded texts automatically?

Example 1 - Between "11" and "22":

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Done with Regular Expression, see below.

Example 2 - Between "^*" and "~|" (extra chars):

ab^*cde21fg~|hi

abc^*de21f~|ghi

abcd^*e21~|fghi

Done with Regular Expression, see below.

Example 3 - From first "1" to begin:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Example 4 - From last "2" to end:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

All help is welcome. :P

Edited by myname1

Share this post


Link to post
Share on other sites
Valuater

StringBetween()

StringLeft()

StringRight()

... ????

automatic is a very open question

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Richard Robertson

In this case, I see regular expressions as the fastest way to do this. For instance, the first could easily be done by using a regular expression replacement of "11.*?22" with "".

What exactly are you looking for?

Share this post


Link to post
Share on other sites
myname1

StringBetween()

StringLeft()

StringRight()

... ????

automatic is a very open question

8)

I don't know what do you mean. :P Can you explain more? :(

In this case, I see regular expressions as the fastest way to do this. For instance, the first could easily be done by using a regular expression replacement of "11.*?22" with "".

What exactly are you looking for?

Thanks for telling me that. Now I figured out how to use regular expression for the first two examples.

Example 1 done by regular expression:

11.*22

Example 2 done by regular expression:

\^\*.*\~\|

Other two are still undone. I tried this for example 3: ^.*1, but it worked like this:

ab11cde21fg22hi

abc11de21f22ghi

abcd11e2122fghi

Anyone know how to do the trick for last two examples? :idea:

Edited by myname1

Share this post


Link to post
Share on other sites
picaxe

$t = "ab11cde21fg22hi" & @CRLF & "abc11de21f22ghi" & @CRLF & "abcd11e2122fghi"
ConsoleWrite(StringRegExpReplace($t, "(^|\r\n|\n)(\D*1)(.*)", "$1$3") & @LF)
ConsoleWrite(StringRegExpReplace($t, "(.*)(2\D*)(\n|\r\n|$)", "$1$3") & @LF)

Share this post


Link to post
Share on other sites
Richard Robertson

It's because you are using the greedy star. Use a lazy star instead. "^.*?1"

Share this post


Link to post
Share on other sites
myname1

$t = "ab11cde21fg22hi" & @CRLF & "abc11de21f22ghi" & @CRLF & "abcd11e2122fghi"
ConsoleWrite(StringRegExpReplace($t, "(^|\r\n|\n)(\D*1)(.*)", "$1$3") & @LF)
ConsoleWrite(StringRegExpReplace($t, "(.*)(2\D*)(\n|\r\n|$)", "$1$3") & @LF)
Is that "$t ="-line necessary? I mean that if I have more than 3 different lines, that would be a quite huge line.

It's because you are using the greedy star. Use a lazy star instead. "^.*?1"

I can't get that lazy star (*?) working. It gives no results. So lazy star isn't supported in all editors like SciTE?

Share this post


Link to post
Share on other sites
Richard Robertson

Scite is an editor, not an interpreter. AutoIt supports the lazy star. It's in the documentation if you had read it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×