1

I'm looking to pull data from some code, to do that I thought I could use regex.

An example of the code I have is:

If IsNumeric(varCS) And IsNumeric(varGTV) And IsNumeric(varTV) Then
    logInfo("GO")
    shtDst.Range("D6").Value = shtSrc.Cells(varCS, varGTV).Value
    shtDst.Range("G104").Value = shtSrc.Cells(varCS, varTV).Value

I would like the result to be:

"D6"
"G104"

The regex I've tried is:

.*(?:Range\((.*)\))?.*

and replacing with:

\1

However this results in just blank lines.

I've looked at lookahead and lookbehind but those seem to require a fixed length string.

I've been using Notepad++ plus various online regex test sites to verify my results.

2 Answers 2

1

Have a try with (don't make Range... optional):

  • Ctrl+H
  • Find what: ^(?:.*?Range\((.+?)\).*?|.+)$
  • Replace with: $1

This is working with the given example.

Sign up to request clarification or add additional context in comments.

1 Comment

this also works and does so more similarly to my original line of thought. When testing this online it made me realise how important modifiers can be, this will only work with /g and /m modifiers. Works out of the box with N++.
0

Try replacing [\S\s]*?("[^"]*?").* with $1\r\n (Example)

3 Comments

Thanks, this works for my first simple example but not on the full code. I've updated my question with an expanded sample.
thanks! this works! I didn't even think to use [\S\s] and . to span multiple lines like that
Only issue with this one is when there are lines at the end without "Range(xx)". All the lines between the last Range line and the end aren't replaced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.