Python program to match string based on user input
<p>I need to write a python program that allows user to enter input
like <code>Apple,Ball</code> and it if matches the line in the file print it.
so far I am able to get this.</p>

<pre><code>import re
import sys
print('Enter the values')
value1=input()

try:
    filenm1="D:\names.txt"
    t=open(filenm1,'r')
    regexp=re.search(value1,line)
    for line in t:
        if regexp:
            print(line)
catch IOerror:
    print('File not opened')
sys.exit(0)
</code></pre>

<p>Sample Input File </p>

<pre><code>Apple
Ball
Stackoverflow
Call
Doll

User input : App
Output : Apple
</code></pre>

<p>now I want to modify this program to search by 
user input : <code>App,Doll</code>
Output : </p>

<pre><code>Apple
Doll
</code></pre>

<p>You can change your loop into this:</p>

<pre><code>import sys
print('Enter the values')
value1=input()
value1=value1.split(',')

try:
    filenm1="D:\names.txt"
    t=open(filenm1,'r')
    for line in t:
        alreadyPrinted = False
        for value in value1:
            if value in line:
                if not alreadyPrinted: #this bit prevents line being printed twice
                    print(line)
                    alreadyPrinted = True
catch IOerror:
    print('File not opened')
sys.exit(0)
</code></pre>

python python-3.x