Question: Hey everyone i am working on a personal project with java (I am still currently learning the language) and have come here with a question or two.

First Question
==============

In my try block i am allowed to ask the user to input a value to be assigned to a variable and in my catch block, if the user inputs a wrong value or skips the entry, it throws an exception and informs the user that a default value has been set. This is a correct way to do this yes?

Code Example
============

(Note: I have many of these try/catch statements working the same way as the one below inside a method.)

```
 try {
        System.out.print("Please enter a value for price of computer: ");
        price = sc.nextFloat();

    } catch (InputMismatchException ex) {    //Catch skip or error
        System.out.println("You entered an invalid value for price, it is assumed to be 0.");
        price = 0F;   //Assign a default value
    }

```

Second Question
===============

When I compile and execue this it doesn't allow me to enter a variable, but instead skips right to the exception. I am not sure what i am missing, so I would love any advice and thanks again to a great community.

Answer: 
The `.+?` quantifier is reluctant (or "lazy"). It means it will match the subpattern it quantifies *one or more times, **but** as few times as necessary to return a valid match*.

You have `(John) (.+?)` pattern and you try to find a match in `John writes about this`. The regex engine finds `John`, places it into Group 1 memory buffer, finds a space, matches it, and then finds `w` in `writes`. The `w` is matched, so the requirement of *one or more* is met. Since the match is already valid, it is returned. You get `John w`.

Now, you add a space after `(.+?)`. The `John` is matched and captured into Group 1 as before, the space is matched with the space in the pattern (again, as before), then `.+?` is executed - finds an empty location before `writes`. It matches this location and goes on to match a space. There is no space at that location, since there is `w`. The regex engine goes back to `.+?` and consumes `w`. Checks if `r` is a space - no, it is not. The engine checks the string this way up to the first matching space and finds it right after `writes`. Thus, your valid match for `(John) (.+?)`  is `John writes` .
Well, if you include the trailing space, you are asking the pattern to match that space as well.

`John w` does not match anymore, because it does not end with a space.

It has to be expanded to `John writes` (note that the match includes the space at the end).