fetching variables from text

The format of Perl is very confusing.

I have the script to get the variables 'username1' and 'password1' from a text file with the following format:

'<b>Username: username1</b> and <b>Password: password1</b>'

Using the script (snippet):

($username) = $page =~ /<b>Username:\s(.*?)<\/b>/i;
($password) = $page =~ /<b>Password:\s(.*?)<\/b>/i;

How do I format this script to get the variables 'username1' and 'password1' from text formatted in this way?  (I've tried everything I can think of):

'Username: </b>username1&nbsp;&nbsp;&nbsp;
<b>Password:</b> password1<br>'

***Note that there is a space between 'Username"' and '</b>' and also a space between '</b>' and 'password1'

The formatting of the script is very confusing.  What do all the backslashes and (\s)'s mean?  Could someone help me to understand the way this is formatted?  Thanks.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Username: </b>username1&nbsp;&nbsp;&nbsp;
<b>Password:</b> password1<br>

Try this:
($username) = $page =~ /Username:\s{0,}<\/b>\s{0,}(.*?)\&/i;
($password) = $page =~ /<b>Password:\s{0,}<\/b>\s{0,}(.*?)<br>/i;

Now, what does this mean. In the first line you search for the string "Username:" followed by 0 or more whitespaces "\s{0,}". Then must follow "</b>" which is written as "<\/b>" because only at the end "/" may appear. Then you look again for 0 or more whitespaces. Finally you look for the password "(.*?)". "." means any character "*" means any number of characters and "?" means minimum matching. All three characters are enclosed with "()" to tell the program to store the value in $username. Minimum matching means that username will be taken to the first "&" character. If "?" was omitted the username would be taken to the last "&" character. The matching for password is almost identical.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GorGor1Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.