Regular Expression Questions on StackOverflow.com

1
answers
0
votes

PHP - Reading ftp text files and extract required data

Tagged: php regex text ftp extract

This is my first php script. I actually code in vb.net.. I am making this licensing system for .net applications. This licensing system has a manager which the admin can easily control and view. Also Iam making a class library to login and register for the same. I have succeeded in doing so using only vb.net code but as the credentials need to be stored inside the application there always is a threat. Using php this problem can be overcomed somewhat :tongue: . So I decided to make the login + register system using this kinda php scripts. I am using a only admin read,write text file instead of a mysql database ( Easily maneagable for all hosting services ). So, I have come up with this following piece of code and I need some help in the confirming the login part. The text file is like this :

username password hwid lastdate membershiptype

All separated by 'space' and one account per line. I hope I have given enough information, If extra information is needed, I will give it.

<?php
$user = addslashes($_GET['username']);
$pass = addslashes($_GET['password']);

  $username = "theusername";  
  $password = "thepassword";  
  $url = "mywebsite.com/file.txt";
  $hostname= "ftp://$username:$password@$url";  
  $contents = file_get_contents($hostname); 
// That gives me the txt file which can only be read and written by the admin
if (strpos($contents,$user) !== false) {
   // Need code here to check if the adjacent word and the $pass are same to establish a successfull login
} else {
 echo "Username does not exist, please register"
}
?>
Details
1
answers
1
votes

Detect matching parentheses

Tagged: javascript regex

Is there an easy way to detect if a string has any of the three following combinations?:

...( ... ) ...
...[ ... ] ...
...< ... > ...

ie, does it contain a pair of matching parentheses, square or angle brackets? I can do it as 3 separate Regex statements. Can it be reduced to one?

Details
3
answers
-1
votes

GREP - Regex +(plus) vs. *(star) performance

Tagged: regex performance grep

Simple question, say I have two regular expressions

rtmp.*?\b/

rtmp.+?\b/

It seems to be negligible difference if any on the tests I have done.

Edit

I understand the technical difference between the two expressions. In my case either will do. As the question states I am simply asking about the performance differance, if any.

Details
1
answers
0
votes

How to grep the pattern within parenthesis?

Tagged: regex grep

Here is the string :

Usage:       xp (UUID: 30503c82-bf04-4f75-ab8f-129b8b350487)

I want to grep this pattern

30503c82-bf04-4f75-ab8f-129b8b350487

I can use grep and sed to pick off it,using like this:

grep \(.*\) -o | sed 's/[()]//g'

can i use only grep to accomplish this opration?

Details
2
answers
1
votes

Convert Notepad++ Regex to PHP Regular Expression

Tagged: php regex preg-replace

I'm trying to convert a Notepad++ Regex to a PHP regular expression which basically get IDs from a list of URL in this format:

http://www.example.com/category-example/1371937-text-blah-blah-blah-2012.html
http://www.example.com/category-example/1471337-text-blah-blah-2-blah-2010.html

Using Notepad++ regex function i get the output that i need in two steps (a list of comma separated IDs)

(.*)/ replace with space

-(.*) replace with comma

Result: 1371937,1471337

I tried to do something similar with PHP preg_replace but i can't figure how to get the correct regex, the below example removes everything except digits but it doesn't work as expected since there can be also numbers that do not belong to ID.

$bb =   preg_replace('/[^0-9]+/', ',', $_POST['Text']);

?>

Which is the correct structure?

Thanks

Details

StackOverflow is Q&A site that's free

Stack Overflow is collaboratively built and maintained by your fellow programmers and is a great place to find answers to trick regular expression problems

To Ask a Question on SO

First, search to see if other developers have had similar problems and if the answers might apply to your question.

Then, create a fiddle, save it and ask your question. By sharing your fiddle, stackoverflow.com members can experiment with your fiddle to help you find the right pattern for your needs.

Active Questions