Regular Expression matching problem on leetcode link: https://leetcode.com/problems/regularexpressionmatching/
Can anyone explain why is ".*" regular expression for "ab" ?
See also questions close to this topic

Want to remove / ( ) . from phone number strings
I want to remove symbols in phone numbers. Sometimes it is in the format of 1514546545 but sometimes it is in (545)(564)(5465) and in sometimes it is in 548.445.8454. I am using
val.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2$3')
for replacing.. but it doesn't remove the dot.What to do remove the dot also? expected output like 5454554545

Java regex to replace all special characters in a String with an underscore also considering removing leading,trailing,multiple underscores
I would need a regular expression to replace all the special characters considering multiple with a single underscore and also not to add trailing and leading underscore if the String contains trailing and leading special characters, I have tried the following but it doesn't seem to work.
String myDefaultString = "_@##%Default__$*_123_" myDefaultString.replaceAll("[\\p{Punct}&&[^_]]", "_")
My eventual result should be
Default_123
where the regular expression needs to consider leading underscore and remove them keeping the underscore in betweenDefault
and123
but also should remove trailing and multiple underscores in between the String.Also tried the following regex
myDefaultString.replaceAll("[^azAZ09_.]+", "_")
But does not seem to work, is what I'm trying to achieve very complicated or it there a better way to do it?

Python regex works in regex tester but not in practical
I need to match the text inside
<p>
element excluding the first<strong>
element from the text.When tested on an online regex tester like https://regexr.com/ it works fine, but when I run on my python script, it doesn't matches anything.
Regex:
<br>(.*)<\/p>$
Text:
<p><strong>Ackee and Saltfish Fritters</strong><br>\n2 cup salted Cod fish, soaked overnight<br>\n2 cloves garlic<br>\n½ medium onion<br>\n1 tsp thyme<br>\n1 tbsp cilantro<br>\n1 scallion, finely chopped<br>\n¼ scotch bonnet pepper, seeds removed<br>\n1 cup all purpose flour<br>\n1 tsp baking powder<br>\n½ cup ackee<br>\n¾ cup water<br>\nCanola oil</p>
Python code:
re.search(r"<br>(.*)<\/p>$", target_string)
Desired result in matches group 1:
\n2 cup salted Cod fish, soaked overnight<br>\n2 cloves garlic<br>\n½ medium onion<br>\n1 tsp thyme<br>\n1 tbsp cilantro<br>\n1 scallion, finely chopped<br>\n¼ scotch bonnet pepper, seeds removed<br>\n1 cup all purpose flour<br>\n1 tsp baking powder<br>\n½ cup ackee<br>\n¾ cup water<br>\nCanola oil

Given N, generate all sequences that start with 0 and end with N, and the diff between neighboring elements are power of 2  in Dynamic Programming
I had the question in the title and I don't know how to optimize the solution with DP. For example, given N=5, all the sequences will be:
[0 1 2 3 4 5] [0 1 2 3 5] [0 1 2 4 5] [0 1 3 4 5] [0 1 3 5] [0 1 5] [0 2 3 4 5] [0 2 3 5] [0 2 4 5] [0 4 5]
I solved it using Recursion https://play.golang.org/p/i2aCQBF01m_T, there are many calculation duplicates and I don't have an idea how to dynamic program it.
For example in:
[0 1 2 3 4 5] [0 1 3 4 5]
the end section
3 4 5
is calculated twice.I thought of having a map like so
map[int][][]int
but the space consumption seemed to me the wrong way to go. 
How much different is dynamic programming from recursion
Mostly I have heard that if you can make a recursion code , you can convert it to a Dynamic programming code, but what is the need to do the same ? And how to convert a recursion code to DP ?

Robot in a Grid  how to get all possible paths
I'm trying to solve this problem:
There is a grid with with r rows and c columns. A robot sitting in top left cell can only move in 2 directions, right and down. But certain cells have to be avoided and the robot cannot step on them. Find a path for the robot from the top left to the bottom right.
The problem specifically asks for a single path, and that seems straight forward:
Having the grid as
boolean[][]
, the pseudocode I have isList<String> path = new ArrayList<String>() boolean found = false void getPath(r, c){ if (!found) { if ( (r or c is outofbounds)  (!grid[r][c]) ) return if (r==0 AND c==0) // we reached found = true getPath(r1, c) getPath(r, c1) String cell = "(" + r + ", " + c + ")" path.add(cell) } }
Though I was wondering how can I get all the possible paths (NOT just the count, but the path values as well). Note that it has r rows and c columns, so its not a nxn grid. I'm trying to think of a DP/recursive solution but unable to come up with any and stuck. It's hard to think when the recursion goes in two ways.
Any pointers? And also any general help on how to "think" about such problems would be appreciated :).