Sign in to follow this  
Followers 0
Who

Can anybody help me with StringRegExp please ?

12 posts in this topic

<UL class=vitals>
<LI class=user-name><A title=Google href="http://google.com">Googl</A> </LI></UL></DIV>
<DIV class=wrapper>
<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>
<P class=datestamp>Sun Dec 30</P>

I'm new with regular expression and from this code, I have tried many times to get out these words : "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30" but it seems that I don't any luck at all. Can anyone give me a working example please ? Thank you very much.

Share this post


Link to post
Share on other sites



<UL class=vitals>
<LI class=user-name><A title=Google href="http://google.com">Googl</A> </LI></UL></DIV>
<DIV class=wrapper>
<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>
<P class=datestamp>Sun Dec 30</P>

I'm new with regular expression and from this code, I have tried many times to get out these words : "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30" but it seems that I don't any luck at all. Can anyone give me a working example please ? Thank you very much.

Do you want to just find if those strings occur, or just the positions of the strings or do you want to find all the occurances?

What have you tried so far?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$aArray0 = _StringBetween($chars1, '\href="', '">', -1, 1);Using SRE
_ArrayDisplay($aArray2, 'StringRegExp Search')

$aArray1 = _StringBetween($chars1, '\<P class=comment>', '\</P>', -1, 1);Using SRE
_ArrayDisplay($aArray2, 'StringRegExp Search')

$aArray2 = _StringBetween($chars1, '<P class=datestamp>', '\</P>', -1, 1);Using SRE
_ArrayDisplay($aArray3, 'StringRegExp Search')

$aArray3 = _StringBetween($chars1, '<LI class=user-name><A title=', 'href="', -1, 1);Using SRE
_ArrayDisplay($aArray3, 'StringRegExp Search')

I have tried this and I got the "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30" but are there anyway for me to find all these occurances with StringRegEXP ? Can you help me please ?

Edited by Who

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

<UL class=vitals>
<LI class=user-name><A title=Google href="http://google.com">Googl…</A> </LI></UL></DIV>
<DIV class=wrapper>
<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>
<P class=datestamp>Sun Dec 30</P>

I'm new with regular expression and from this code, I have tried many times to get out these words : "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30" but it seems that I don't any luck at all. Can anyone give me a working example please ? Thank you very much.

This?:

Dim $Txt = FileRead("c:\Test\test.txt")

$str = StringRegExpReplace($Txt, '(?i)Google|http://google.com|<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif"|border=0><BR>Hello|Sun Dec 30', "")

MsgBox(0, "", $str)

FileClose($Txt)
Edited by rasim

Share this post


Link to post
Share on other sites

<UL class=vitals>
<LI class=user-name><A title= href="">Googl</A> </LI></UL></DIV>
<DIV class=wrapper>
<P class=comment> </P>
<P class=datestamp></P>

I have tried as you told and here is the output, but I'm going to get out the "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30". Can you explain it for me please ?

Share this post


Link to post
Share on other sites

Who

Hello! Sorry, my knowing english is very bad. What you need: exclude said words or get only this words?

:)

Share this post


Link to post
Share on other sites

I just want to get the words : "Google", "http://google.com", "<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello", "Sun Dec 30" but I'm totally a newbie. Can you help me please ? Thank you very much.

Share this post


Link to post
Share on other sites

I just want to get the words

Do you want them into array?

Check this:

#include <Array.au3> ;Only for check the results

$String = '<UL class=vitals>' & @CRLF & _
    '<LI class=user-name><A title=Google href="http://google.com">Googl…</A> </LI></UL></DIV>' & @CRLF & _
    '<DIV class=wrapper>' & @CRLF & _
    '<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>' & _
    @CRLF & '<P class=datestamp>Sun Dec 30</P>'

$aRet = StringRegExp($String, '(?i)(?s)<A title=(.*).*href="(.*)".*P class=comment>(.*)</P>.*<P class=datestamp>(.*)</P>', 3)

_ArrayDisplay($aRet)

;We got this returned:

    ;$aRet[0] = Google
    ;$aRet[1] = http://google.com
    ;$aRet[2] = <STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello
    ;$aRet[3] = Sun Dec 30

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Thank you very much but when I doubled the $String to :

$String = '<UL class=vitals>' & @CRLF & _
    '<LI class=user-name><A title=Google href="http://google.com">Googl</A> </LI></UL></DIV>' & @CRLF & _
    '<DIV class=wrapper>' & @CRLF & _
    '<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>' & _
    @CRLF & '<P class=datestamp>Sun Dec 30</P><UL class=vitals>' & @CRLF & _
    '<LI class=user-name><A title=Google href="http://google.com">Googl</A> </LI></UL></DIV>' & @CRLF & _
    '<DIV class=wrapper>' & @CRLF & _
    '<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>' & _
    @CRLF & '<P class=datestamp>Sun Dec 30</P>'

then the result is :

[0]|Google href="http://google.com">Googl</A> </LI></UL></DIV>
<DIV class=wrapper>
<P class=comment><STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello</P>
<P class=datestamp>Sun Dec 30</P><UL class=vitals>
<LI class=user-name><A title=Google 
[1]|http://google.com
[2]|<STRONG>Hello</STRONG><IMG src="http://www.google.com.vn/logos/holiday07_5.gif" border=0><BR>Hello
[3]|Sun Dec 30

So what is wrong with this ? Can you tell me please ?

Share this post


Link to post
Share on other sites

So what is wrong with this ?

Well, this is different string, and need a little different pattern:

StringRegExp($String, '(?i)(?s)<A title=(.*?) href="(.*?)">.*P class=comment>(.*?)</P>.*<P class=datestamp>(.*?)</P>', 3)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

It works now, thank you very much for your help :)

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  
Followers 0