HF nava
HF nava

Reputation: 9

Regex to get url from a text file

Currently i am working with c# project.In windows.I have a text file that contains the following text. I want to grab this http://google.com/en/login or just google.com

Sometime the url may changes like below 

SiteURL=http://  google.com/en/login
SiteURL=https:// google.  com/en/login
SiteURL=http:// www.google. com/en/login
SiteURL=https:// www.google. com/en/login
Note: There are no spaces in url site not allowing me to post more than 2 links.
Even though i want to grab text after siteurl= or just google.com

Thanks 
I have zero knowledge in regex.This is a small part what i need in my project.Thanks

The below text present in text file.While reading the text file i want to garb that url.Thank you very much

    [Wordlist]
UserIndex=1
PassIndex=2
EmailIndex=0
543835182C9E9FFF099CD106D4253D3A=100

[Settings]
SiteURL=http://google.com/en/login
Timeout=20
WaitBot=0
ResolveHost=0
ComboFilter=0
ComboMode=0
EmailFilter=0
EmailMode=0
UsernameStart=6
UsernameEnd=8
InvalidChars=
AllowedChars=
Letters=0
Digits=0
Alpha=0
Email=0
LowerUpper=0
LetterDigit=0
SpeciaChar=0
PasswordStart=6
PasswordEnd=8
PasswordInvalidChars=
PasswordAllowedChars=
PasswordLetters=0
PasswordDigits=0
PasswordAlpha=0
PasswordEmail=0
PasswordLowerUpper=0
PasswordLetterDigit=0
PasswordSpeciaChar=0
ProxyActivate=10
ProxyRatio=4
ProxyCombo=0
WaitTime=1
BanWindowWidth=1
BanWindowRatio=10
BanWindowProxies=10
blnNoProxies=1
HTTPHeader=<ACTION> <FORM ACTION> <HTTP VERSION>|Accept: */*|User-Agent: <USER AGENT>|Host: <HOST>|Pragma: no-cache|Connection: keep-alive|
RequestMethod=2
Referer=0
POSTData=login=<USER>&password=<PASS>&referer=

[Fake]
AfterFP=1
blnSuccess=0
SuccessRetries=3
blnProcessErrors=0
blnCompleteNot=1
EnableConHits=0
ConHits=0
FollowRedirect=1
EnableConLength=0
ConLength=-1
SourceTags=1
UserField=0
HTTPFollow=1
blnForbToOK=0
ForbToOkLength=1000
blnBadOcrCode=0
BadOcrCodeRetries=3

[Keywords]
EnableHeaderSuccess=0
EnableHeaderBan=0
EnableHeaderFail=0
EnableHeaderRetry=0
HeaderSuccess=
HeaderBan=
HeaderFail=
HeaderRetry=
EnableGlobalSourceRetry=1
EnableSourceSuccess=1
EnableSourceBan=0
EnableSourceFail=1
EnableSourceRetry=0
SourceSuccess=>Logout
SourceBan=
SourceFail=Fail login
SourceRetry=

[Form]
IAParse=0
LoginPostData=
LoginMethod=1
LoginHeader=0
Action=http://google.com/en/login
Username=login
Password=password
Email=
AddData=referer=
CustomData=
NoIndex=
Cookie=identity=f03982a8f9c847e9a23cb818912f7a51; symfony=0el04cmspgogapkkt6k26uo3b4
IAction=-1
IUser=-1
IPass=-1
IEmail=-2
ICaptcha=-1
ReqReferer=
ReqCookie=
AjaxURL=
AjaxPOSTData=
AjaxData=
AjaxParsingCode=
RefData=
ParsingCode=
FormRedirectUrl=
RedPostData=
RedKeys=
DataDesc=Cracked BY ***************** Team = Your account is&Valid to
CaptureParsingCode=s: |<|#00|#00|0|#00|#00|0&o: | |#00|#00|0|#00|#00|0
RefreshSession=0
RefreshCookie=0
FormHeader=0
AjaxHeader=0
RedHeader=0
IAMethod=2
POSTMethod=2
RedMethod=1
ImageAfterAjax=0
blnBasic=0
FollowRedirectsOnIA=0
FollowRedirectsOnRed=1

[Ajax]
Variables=
PostElements2=
RedURL=

[OCR]
OCRMode=0
URLMode=0
ImageURLID=||
Captcha=
OCRKey=
RefreshCaptcha=0
blnContrast=0
blnBrightness=0
blnSaturation=0
blnThreshold=0
blnInvert=0
blnNoise=0
blnIsolate=0
blnResize=0
blnBorder=0
blnCharExtract=0
blnRemoveColors=0
blnStringFilter=0
blnLetter=1
blnDigits=1
blnBlur=0
blnReconstruct=0
blnLower=0
blnUpper=0
blnRemoveLines=0
blnMultiChar=0
blnCharTable=0
blnPalette=0
blnCharResize=0
blnCharSubExtraction=0
blnThreeImages=0
blnGif=0
blnCompute=0
blnBorderPre=0
Contrast=0
Brightness=0
Saturation=0
Threshold=0
Noise=1
Isolate=1
Resize=2
BorderLeft=0
BorderTop=0
BorderRight=0
BorderBottom=0
CharExtractMinBlack=0
CharExtractMaxBlack=1
CharExtractMinWidth=1
CharRotateMax=0
CharRotateSteps=5
MinLength=1
MaxLength=10
BlurRadius=1
CharExtractMaxWidth=33
CharWidthMinBlack=2
CharSpace=1
Range=0
InvertDensity=0
InvertLength=20
LineCurvatureMax=4
LineWidthMax=13
CharResize=1
CharHeight=13
GifStart=2
GifOffset=2
BorderLeftPre=0
BorderTopPre=0
BorderRightPre=0
BorderBottomPre=0
CharBorderH=5
CharBorderV=5
CharRotateBorder=5
CharExtractMinHeight=1
VerticalRejoin=30
CharExclude=
SpecialChars=
Colors=
Colors2=
Lines=Min Length: 2, Max Width: 5, Horizzontal
Language=eng

Upvotes: 0

Views: 257

Answers (1)

Max
Max

Reputation: 217

var pattern = @"(?<=SiteURL=).+";
string text = System.IO.File.ReadAllText(path); //your path needs to be added here (e.g. @"C:\Users\userx\Downloads\file.txt")
var match = System.Text.RegularExpressions.Regex.Match(text, pattern);

The link you're looking for is stored in the variable called "match".

Upvotes: 1

Related Questions