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

@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

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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jahar
      Hi,
      I am new to Autoit, Kindly guide me. I wanted to send a message with HTTP/GET to the URL https://ghsff.it/. How to do so?
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
    • By ni3dprint
      Hi folks, 
      Thank you so much in advance for your help!  I've been using AUTOIT for manipulating gcode.  So far I've just worked through the excellent help examples and although I'm sure the resulting code is clumsy it has functioned  
      However now I'm trying to improve and advance things and I've stumbled across REGEX.. and I'm a bit stuck.  What I would like to be able to do is to 'move'/'transform' the gcode in a file and re-write it to a new file.  I only need to move it in one direction(X).  At the heart of this I need a script to extract all the X values and then ADD or SUBTRACT an adjustment factor to transform and rewrite the code accordingly.
      So far using an example script and an example input -
      Func Test2()
      Local $iMove = -4
          Local $sInput = '"G1 X45.036 Y6.934 F7800.000 G1 Z0.600 F7800.000 G1 F900 G1 X48.036 Y1.076 E0.58925"'
          Local $sOutput = StringRegExpReplace($sInput, '(?<=[X])\d+.\d+', '\0')
          Display($sInput, $sOutput)
      EndFunc   ;==>Test2
      This identifies the correct values i.e 45.036 and 48.036 but is there a way to dyamically adjust them before they are replaced, by for example a factor of -4 ($iMove above).  So far I can't seem to do math on the '\0' value i.e '\0'+ -4 ?
      Many thanks for your time and expertise!
       
    • By HariKara
      I have a script that seems to launch perfectly fine with IECreate, however, I want to launch the Browser and a specific URL with the RunAs command. I fairly new to AutoIT and wanted to know if someone can point me in the right direction.
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = _IECreate($sURL)
      The above launches the website correctly with the correct URL, however, I have tried the below and this fails to load and browser?
      #include <AutoItConstants.au3>
      ;========================
      $oSleep = "200"
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = RunAs($args("username"), $args("domain"), $args("logonpassword"), "", "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://somewebsite.com/DODA/admin/job.aspx")
      _IELoadWait($oIE)
       
      I get the following error back?
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
×
×
  • Create New...