Jump to content

Recommended Posts

hello sirs

i've some questions about StringRegExpReplace i hope you can help me

 

i tried to make a function that give me the host of the url and other give me the url with out host

for example i've this link

https://www.example.com/vb/result.php

i need the first give me the

example.com

and the other give me 

/vb/result.php

i find that

$s_source = "https://www.google.com/vb/index.php"
Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1')
Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1')
msgBox(64, $s_Host, $s_Page)

 

but i found some problems i need your help to correct it

first: when i get the host if the url has www i want to remove it

second: if the url with out host did not have other things 

i need the result to be ""

e.g

https://www.example.com

the first i want it

example.com

and the second i want it to be ""

i hope that you can help me

thanks in advance

Share this post


Link to post
Share on other sites
Posted (edited)

@nacerbaaziz

Use StringRegExp() with the flag $STR_REGEXPARRAYGLOBALMATCH (StringConstants.au3 needed), which will returns an array for each group found based on the pattern set.

This pattern should extract what needed:

'https?:\/\/(?:www\.)?([^\/]+)(.*)'

Post more samples of URLs if you have any :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

For the first : put "www." in a non-capturing group and make it optional
For the second : your regex needs an alternative, "/.*" or end of string

$s_source = "https://www.google.com" ;/vb/index.php"
Local $s_Host = StringRegExpReplace($s_Source, '.*://(?:www.+)?(.*?)(/.*|$)', '\1')
Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*|$)', '\1')
msgBox(64, $s_Host, $s_Page)

Edit
Oops Francesco answered first :sweating:

Edited by mikell

Share this post


Link to post
Share on other sites
2 minutes ago, FrancescoDiMuro said:

@nacerbaaziz

Use StringRegExp() eith the flag $STR_REGEXPARRAYGLOBALMATCH (StringConstants.au3 needed), which will returns an array for each group found based on the pattern set.

This pattern should extract what needed:

'https?:\/\/(?:www\.)?([^\/]+)(.*)'

Post more samples of URLs if you have any :)

can you convert the example that i gave you in top please? because i don't know allot on regEx

thx in advance

Share this post


Link to post
Share on other sites

sir

@mikell

am sory

but when i tried to put a url that start with www.example.com

the www diden't removed

can you please try to added to me?

am realy sorry

 

Share this post


Link to post
Share on other sites
Local $sSource = "https://www.google.com/vb/index.php"
Local $aRes = StringRegExp($sSource, '://(?:www\.)?(.*?)(/.+|$)', 3)
MsgBox(64, "URL", "Host = " & $aRes[0] & @LF & "Page = " & $aRes[1])

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

hello
the url that i need to manage it i couldn't know it
because the user who enter the url
for that i have 3 ways
first the url is www.url.com/xxx
the second the url is http(s)://url.com/xxx
the third the url is http(s);://www.url.com/xxx
for that i need to add These possibilities to this example

$s_source = "https://www.google.com/vb/index.php"
or
$s_source = "https://google.com/vb/index.php"
or
$s_source = "www.google.com/vb/index.php"

Local $s_Host = StringRegExpReplace($s_Source, '.*://(?:www.)?(.*?)(/.*|$)', '\1')
Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*|$)', '\1')
msgBox(64, $s_Host, $s_Page)
i hope that can any one help me
I apologize for my delay in understanding and my slow response
thanks in advance

Share this post


Link to post
Share on other sites
Posted (edited)
Local $aURLs = [ _
    "https://www.google.com/vb/index.php", _
    "https://www.google.com/", _
    "https://www.google.com", _
    "https://google.com/vb/index.php", _
    "https://google.com/", _
    "https://google.com", _
    "www.google.com/vb/index.php", _
    "www.google.com/", _
    "www.google.com", _
    "google.com/vb/index.php", _
    "google.com/", _
    "google.com" _
]

Local $aRes
For $Url In $aURLs
    $aRes = StringRegExp($URL, '(?://)?(?:www\.)?(.*?)(/.+|$)', 3)
    ConsoleWrite("URL = " & $URL & @LF & "Host = " & $aRes[0] & @LF & "Page = " & $aRes[1] & @LF & @LF)
Next

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

hello again

from all your answers i got this way

it worked with out any problem

this is the way that worked with me

before that please accept my greetings to all of you

and Thank you all for your valuable responses.

here is the code

$s_source = "https://www.mx-blind.com/vb/index.php"
Local $s_Host = StringRegExpReplace($s_Source, '(?:.*://)?(?:www\.)?(.*?)(/.*|$)', '\1')
Local $s_Page = StringRegExpReplace($s_source, '(?:.*://)?(?:www\.)?.*?(/.*|$)', '\1')
msgBox(64, $s_Host, $s_Page)

 

Share this post


Link to post
Share on other sites

good morning sirs.
today i've an other question in the same function
i created a html reader
and i need a way to extract the html link
i found the html UDF
but there is a problem
i want to get the url name
e.g i've
$source = '<a href="https://example.com/">the web site</a>
is there any way to get the Link and the name from the tag
here is what i tried to read the name
$s_Name = StringRegExpReplace($source, '(?:<a.*?>)?(?:<.*?>)', '\1')
sometimes it works, and it doesn't work a lot of times.

note
the url can be different from one to an other one
e.g
can be
<a href="https://example.com" id="i" class="newclass"><Div class="nameClass">the web site</div></a>
or
<a class="class" href="https://example.com" id="i">the web site</a>
for that i couldn't use the _StringBetween or a  simple stringReplace
for that i hope any one have any other way.
thanks in advance

Share this post


Link to post
Share on other sites

that worked for me

thank you

what about the link title their isn't a way to get it

please if any one have a way give it to me

Share this post


Link to post
Share on other sites

good morning

sir

@mikell

the url is worked

what about how to get the url name

i tried to use the code that i gave it above but some times it not working

i hope if any one can help me to do that.

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

  • Similar Content

    • By genius257
      Inspired by PHP's preg_split.
      Split string by a regular expression.
      Also supports the same flags as the PHP equivalent.
      v1.0.1
       
      Example:
      #include "StringRegExpSplit.au3" StringRegExpSplit('splitCamelCaseWords', '(?<=\w)(?=[A-Z])') ; ['split', 'Camel', 'Case', 'Words']  
    • By jmp
      i am trying to get number from string using this code :
      #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058
      But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

       
    • By jmp
      I am adding labour charge to total paid amount using : 
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData3 = _IETableWriteToArray ($oTable) Local $sitem1 = $aTableData3[5][1] Local $sitem2 = $aTableData3[5][2] Local $lcharge = "10" ;add manualy using inputbox, becuase not generating online Local $atotPric = "Payable Total Price " Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.Innertext = $atotPric Then $iatotPric = $oTd.NextElementSibling.innertext MsgBox (0, "2", $iatotPric) EndIf Next $irCtotal = StringFormat("%.2f", $sitem1 + $sitem2 + $lcharge) $crTotp = StringReplace(_IEBodyReadHTML($oIE), $iatotPric, $irCtotal) _IEBodyWriteHTML ($oIE, $crTotp) But, It was also changing Total price, I want to change only Payable Total Price.

    • By nacerbaaziz
      hello sirs
      please i want to use the WinHttp to get the google drive file title using the api
      i searched in the forom but i didn't found any Google drive api UDF
      for that i liked to ask you for that
      i had read the google drive api documentation but i couldn't do it
      please help me
      here is the api doc
      note i've got the apikey and i have the file id
      what i want is to get the title of the file (the file name)
      because i want to download the files from the google drive using the autoit
      please help me for that
      am sorry because i didn't gave you any example or what i tried but all what tried was  failed
      thanks in advance
    • By iAmNewbe
      I created an application to catch keyboard programmed keys.  Some of the keys open URL's via ShellExecute and then they open in the default browser.

      The problem I am having is that when the browser is opened in this manner 3rd party applications such as Logitech Setpoint for Logitech mouse and keyboards and programs like auto password form filling stop working with the browser.  In the mouse specific situation the Cruise Up and Cruise Down buttons, normally back and forward, do not work. If I open the browser manually via the browsers icon and then press the keyboard buttons to open the web page everything works normally.

      I have two questions:

      1:  Why does 
      ShellExecute("http://www.autoitscript.com") when the browser is not open and then is launched, via the above line, cause third party apps to not be able to interface with the browser?


      2:  What is a better way to launch URL's if not via ShellExecute?


      The application is NOT using #RequireAdmin and is not 64bit.
×
×
  • Create New...