Regex - how to apply for multiline?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
wootshuska
Posts: 23
Joined: Mon Mar 07, 2016 12:04 am

Regex - how to apply for multiline?

Post by wootshuska » Tue May 03, 2016 3:32 pm

I want to extract data from html. The thing is, that i cant extract 2 of strings which are on the top, and on the bottom of my pattern.

I want to extract 23423423423 and 1234523453245 but only, if there is string Allan between:

Code: Select all

    <h4><a href="/Profile/23423423423.html">@@@@@@</a>  </h4> said12:49:32
            </div>

                                <a href="javascript:void(0)" onclick="replyAnswer(@@@@@@@@@@,'GET','');" class="reportLink">
                    report                    </a>
                        </div>

        <div class="details">
                            <p class="content">


                       Hi there, Allan.



                                </p>

            <div id="AddAnswer1234523453245"></div>
Of course, i can do something like this: Profile\/(\d+).*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*Allan.*\s*.*\s*.*AddAnswer(\d+). But the code is horrible. Is there any solution to make it shorter?

I was thinking about:

Code: Select all

Profile\/(\d+)(.\sAllan)*AddAnswer(\d+)
or

Code: Select all

Profile\/(\d+)(.*Allan\s*)*AddAnswer(\d+)
and:

Code: Select all

/Profile\user_/(\d+).+Allan.+AddAnswer(\d+)/m
but none of wchich works properly. Do you have any ideas?


-----
Firefox 44.0.2
iMacros for Firefox 8.9.6
VERSION BUILD=8961227 RECORDER=FX
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Regex - how to apply for multiline?

Post by Trax » Tue May 03, 2016 4:10 pm

'g' is a flag that means golbal, tried to use that ?

Code: Select all

/whatever/g
A working sample :

Code: Select all

/\d{3,}/g

\d - any digit/number
{3,} - anything with 3 or more consecutive ,in this case digits.
g - global
wootshuska
Posts: 23
Joined: Mon Mar 07, 2016 12:04 am

Re: Regex - how to apply for multiline?

Post by wootshuska » Tue May 03, 2016 4:52 pm

I managed something like that:

Code: Select all

SEARCH SOURCE=REGEXP:"/Profile/user_(\d+).+AddAnswer(\d+)/g" IGNORE_CASE=YES EXTRACT=$1
its not working :/
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Regex - how to apply for multiline?

Post by Trax » Wed May 04, 2016 12:49 pm

Since you want to check for 'allan' before using regex maybe it would be easier to split the task in two:

1. Search for the name
2. Retrieve the data

I would use jQuery and do something like :

Code: Select all

var content = $('.details .content').text(); // You can just use iMacros text extract for this text too.

if (content.match/Allan/gi) {
    // retrieve whatever you need
}
Keep in mind, this requires a .js file(javascript) and jQuery which sometimes complicates things.
Post Reply