Jump to content

How to grab these (a very difficult pattern)


Go to solution Solved by mikell,

Recommended Posts

$str =  '08121901000 - 022 99621221 - www.adv08.com</div><!--description-->' & @CRLF & _
        'call: 08 55555 6111 (Dadan)</div><!--description-->' & @CRLF & _
        '<img src="/getattachment/9630832c-3d4e-4e5b-af83-ee8bb6e9dbad/Show.aspx?maxSideSize=60" alt="Bemper Mitsubishi Pajero 2002"/></div><!--slide-thumbnail-->' & @CRLF & _
        '<a href="/Asesoris-car/Aksesoris-other/Bemper-Mitsubishi-Pajero-2002-512066" target="_blank">Bemper Mitsubishi Pajero 2002</a><br />Bemper Mitsubishi Pajero 2002 4x4. Import from Australia, brand new, eks stock, call Raymond 0812711451</div><!--description-->' & @CRLF & _
        'Joe: 0878 6131 7111' & @CRLF & _
        'Text Me : 0822 8124 8624' & @CRLF & _
        '081251136118(james)' & @CRLF & _
        '7123408,081288778899' & @CRLF & _
        '022 99621221,08121901012 - www.adv808.com</div><!--description-->' & @CRLF & _
        '99621081,08111901112 - www.adv808.com</div><!--description-->' & @CRLF & _
        'For more info, please call 081233666201 / 081731161201' & @CRLF & _
        'For more info, please call 081233666201' & @CRLF & _
        '<div class="titl listtitl"><a href="/car/acce-Others/VIMAX-PILL-ORIGINAL-(4)">VIMAX PILL ORIGINAL PERMANENT (081126747616)</a></div>' & @CRLF & _
        'there is nothing to grab here 08klajsa212222' & @CRLF & _
        'there is no valid pattern to grab here because length is 9 081123456' & @CRLF

I would like to get number that start with "08" and length between 10~12, eg:

08121901000 from "08121901000 - 022 99621221 - www.adv08.com</div><!--description-->"

08555556111 from "call: 08 55555 6111 (Dadan)</div><!--description-->"

0812711451 from "<a href="/Asesoris-car/Aksesoris-other/Bemper-Mitsubishi-Pajero-2002-512066" target="_blank">Bemper Mitsubishi Pajero 2002</a><br />Bemper Mitsubishi Pajero 2002 4x4. Import from Australia, brand new, eks stock, call Raymond 0812711451</div><!--description-->"

087861317111 from "Joe: 0878 6131 7111" & @CRLF

082281248624 from "Text Me : 0822 8124 8624" & @CRLF

081251136118 from "081251136118(james)" & @CRLF

081288778899 from "7123408,081288778899" & @CRLF

08121901012 from "022 99621221,08121901012 - www.adv808.com</div><!--description-->" & @CRLF

081233666201 and 081731161201 from "For more info, please call 081233666201 / 081731161201" & @CRLF

081233666201 from "For more info, please call 081233666201" & @CRLF

081126747616 from "<div class="titl listtitl"><a href="/car/acce-Others/VIMAX-PILL-ORIGINAL-(4)">VIMAX PILL ORIGINAL PERMANENT (081126747616)</a></div>" & @CRLF

 

I think this is a very difficult RegExp pattern, isn't it? Or how to grab that without RegExp?

Thanks

Edited by michaelslamet
Link to comment
Share on other sites

_Test("08121901000 - 022 99621221 - www.adv08.com</div><!--description-->")
 _Test("call: 08 55555 6111 (Dadan)</div><!--description-->")
 _Test('<a href="/Asesoris-car/Aksesoris-other/Bemper-Mitsubishi-Pajero-2002-512066" target="_blank">Bemper Mitsubishi Pajero 2002</a><br />Bemper Mitsubishi Pajero 2002 4x4. Import from Australia, brand new, eks stock, call Raymond 0812711451</div><!--description-->')
_Test("Joe: 0878 6131 7111" & @CRLF)
_Test("Text Me : 0822 8124 8624" & @CRLF)
_Test("081251136118(james)" & @CRLF)
_Test("7123408,081288778899" & @CRLF)
_Test("022 99621221,08121901012 - www.adv808.com</div><!--description-->" & @CRLF)
_Test("For more info, please call 081233666201 / 081731161201" & @CRLF)
_Test("For more info, please call 081233666201" & @CRLF)
_Test('<div class="titl listtitl"><a href="/car/acce-Others/VIMAX-PILL-ORIGINAL-(4)">VIMAX PILL ORIGINAL PERMANENT (081126747616)</a></div>' & @CRLF)


Func _Test($StringTst)

$string = stringstripws($StringTst , 8)
$aString = stringregexp($string , "08\d+" , 3)

For $i = 0 to ubound($aString) - 1
If StringLen($aString[$i]) > 9 And StringLen($aString[$i]) < 13 Then msgbox (0, '' , $aString[$i])
next

EndFunc

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

michaelslamet,

This seems to work: :)

#include <Array.au3>

Global $aString[] = ["08121901000 - 022 99621221 - www.adv08.com</div><!--description-->", _
              "call: 08 55555 6111 (Dadan)</div><!--description-->", _
              '<a href="/Asesoris-car/Aksesoris-other/Bemper-Mitsubishi-Pajero-2002-512066" target="_blank">Bemper Mitsubishi Pajero 2002</a><br />Bemper Mitsubishi Pajero 2002 4x4. Import from Australia, brand new, eks stock, call Raymond 0812711451</div><!--description-->', _
              "Joe: 0878 6131 7111", _
              "Text Me : 0822 8124 8624", _
              "081251136118(james)", _
              "7123408,081288778899", _
              "022 99621221,08121901012 - www.adv808.com</div><!--description-->", _
              "For more info, please call 081233666201 / 081731161201", _
              "For more info, please call 081233666201", _
              '<div class="titl listtitl"><a href="/car/acce-Others/VIMAX-PILL-ORIGINAL-(4)">VIMAX PILL ORIGINAL PERMANENT (081126747616)</a></div>']

For $i = 0 To UBound($aString) - 1
    ; Strip all spaces to make sure the digits are sequential
    $aRet = StringRegExp(StringStripWS($aString[$i], 8), "(08\d{8,10})", 3)
    _ArrayDisplay($aRet, "", Default, 8)
Next
SRE decode:

(08\d{8,10}) - Capture any string beginning with 08 and followed by 8 to 10 other digits

3            - Create an array of all instances
Does that do what you want? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Solution

#include <Array.au3>

$str =  '08121901000 - 022 99621221 - www.adv08.com</div><!--description-->' & @CRLF & _ 
        'call: 08 55555 6111 (Dadan)</div><!--description-->' & @CRLF & _  
       '<img src="/getattachment/9630832c-3d4e-4e5b-af83-ee8bb6e9dbad/Show.aspx?maxSideSize=60" alt="Bemper Mitsubishi Pajero 2002"/></div><!--slide-thumbnail-->' & @CRLF & _  
       '<a href="/Asesoris-car/Aksesoris-other/Bemper-Mitsubishi-Pajero-2002-512066" target="_blank">Bemper Mitsubishi Pajero 2002</a><br />Bemper Mitsubishi Pajero 2002 4x4. Import from Australia, brand new, eks stock, call Raymond 0812711451</div><!--description-->' & @CRLF & _ 
        'Joe: 0878 6131 7111' & @CRLF & _  
       'Text Me : 0822 8124 8624' & @CRLF & _  
       '081251136118(james)' & @CRLF & _  
       '7123408,081288778899' & @CRLF & _ 
        '022 99621221,08121901012 - www.adv808.com</div><!--description-->' & @CRLF & _ 
        '99621081,08111901112 - www.adv808.com</div><!--description-->' & @CRLF & _ 
        'For more info, please call 081233666201 / 081731161201' & @CRLF & _ 
        'For more info, please call 081233666201' & @CRLF & _ 
        '<div class="titl listtitl"><a href="/car/acce-Others/VIMAX-PILL-ORIGINAL-(4)">VIMAX PILL ORIGINAL PERMANENT (081126747616)</a></div>' & @CRLF & _ 
        'there is nothing to grab here 08klajsa212222' & @CRLF & _ 
        'there is no valid pattern to grab here because length is 9 081123456' & @CRLF

$aRet = StringRegExp(StringStripWS($str, 8), "08\d{8,10}", 3)
_ArrayDisplay($aRet)

The results are slightly different than Melba's because this code uses the string from your first post

:)

Edited by mikell
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...