diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py
index 2b6bb6ed3..301a35844 100644
--- a/nipype/pipeline/engine/utils.py
+++ b/nipype/pipeline/engine/utils.py
@@ -1050,7 +1050,17 @@ def generate_expanded_graph(graph_in):
             expansions = defaultdict(list)
             for node in graph_in.nodes():
                 for src_id in list(old_edge_dict.keys()):
-                    if node.itername.startswith(src_id):
+                    # Drop the original JoinNodes; only concerned with
+                    # generated Nodes
+                    if hasattr(node, 'joinfield'):
+                        continue
+                    # Patterns:
+                    #   - src_id : Non-iterable node
+                    #   - src_id.[a-z]\d+ : IdentityInterface w/ iterables
+                    #   - src_id.[a-z]I.[a-z]\d+ : Non-IdentityInterface w/ iterables
+                    #   - src_idJ\d+ : JoinNode(IdentityInterface)
+                    if re.match(src_id + r'((\.[a-z](I\.[a-z])?|J)\d+)?$',
+                                node.itername):
                         expansions[src_id].append(node)
             for in_id, in_nodes in list(expansions.items()):
                 logger.debug("The join node %s input %s was expanded"

Issue with node name that starts with another node's name
I think the [line ~801 in util.py](https://github.com/nipy/nipype/edit/master/nipype/pipeline/engine/utils.py#L801) should be something like this:

            for node in graph_in.nodes():
                for src_id, edge_data in list(old_edge_dict.items()):
                    if node.itername.startswith(src_id + '.'):  # <-- add '.' to src_id
                        expansions[src_id].append(node)

For example, if the node "input" feeds into "input_files", the "input_files" can be included if you just test for node.itername.startswith(src_id). This change would prevent "input_files" from being included. 

Edit: removed last part of my comment.
diff --git a/nipype/pipeline/engine/tests/test_join.py b/nipype/pipeline/engine/tests/test_join.py
index 436d29d9e..54ff15048 100644
--- a/nipype/pipeline/engine/tests/test_join.py
+++ b/nipype/pipeline/engine/tests/test_join.py
@@ -7,11 +7,9 @@ from __future__ import (print_function, division, unicode_literals,
                         absolute_import)
 from builtins import open
 
-import os
-
 from ... import engine as pe
 from ....interfaces import base as nib
-from ....interfaces.utility import IdentityInterface
+from ....interfaces.utility import IdentityInterface, Function, Merge
 from ....interfaces.base import traits, File
 
 
@@ -612,3 +610,20 @@ def test_nested_workflow_join(tmpdir):
     # there should be six nodes in total
     assert len(result.nodes()) == 6, \
         "The number of expanded nodes is incorrect."
+
+
+def test_name_prefix_join(tmpdir):
+    tmpdir.chdir()
+
+    def sq(x):
+        return x ** 2
+
+    wf = pe.Workflow('wf', base_dir=tmpdir.strpath)
+    square = pe.Node(Function(function=sq), name='square')
+    square.iterables = [('x', [1, 2])]
+    square_join = pe.JoinNode(Merge(1, ravel_inputs=True),
+                              name='square_join',
+                              joinsource='square',
+                              joinfield=['in1'])
+    wf.connect(square, 'out', square_join, "in1")
+    wf.run()

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
click==8.0.4
configparser==5.2.0
decorator==4.4.2
funcsigs==1.0.2
future==1.0.0
importlib-metadata==4.8.3
iniconfig==1.1.1
isodate==0.6.1
lxml==5.3.1
mock==5.2.0
networkx==2.5.1
nibabel==3.2.2
-e git+https://github.com/nipy/nipype.git@e6792158568a51f0e6cdef77c6ca12ab6266a7dd#egg=nipype
numpy==1.19.5
packaging==21.3
pluggy==1.0.0
prov==1.5.0
py==1.11.0
pydot==1.4.2
pydotplus==2.0.2
pyparsing==3.1.4
pytest==7.0.1
python-dateutil==2.9.0.post0
rdflib==5.0.0
scipy==1.5.4
simplejson==3.20.1
six==1.17.0
tomli==1.2.3
traits==6.4.1
typing_extensions==4.1.1
zipp==3.6.0

name: nipype
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - click==8.0.4
      - configparser==5.2.0
      - decorator==4.4.2
      - funcsigs==1.0.2
      - future==1.0.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - isodate==0.6.1
      - lxml==5.3.1
      - mock==5.2.0
      - networkx==2.5.1
      - nibabel==3.2.2
      - numpy==1.19.5
      - packaging==21.3
      - pluggy==1.0.0
      - prov==1.5.0
      - py==1.11.0
      - pydot==1.4.2
      - pydotplus==2.0.2
      - pyparsing==3.1.4
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - rdflib==5.0.0
      - scipy==1.5.4
      - simplejson==3.20.1
      - six==1.17.0
      - tomli==1.2.3
      - traits==6.4.1
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/nipype

nipype/pipeline/engine/tests/test_join.py::test_name_prefix_join
nipype/pipeline/engine/tests/test_join.py::test_join_expansion nipype/pipeline/engine/tests/test_join.py::test_node_joinsource nipype/pipeline/engine/tests/test_join.py::test_set_join_node nipype/pipeline/engine/tests/test_join.py::test_unique_join_node nipype/pipeline/engine/tests/test_join.py::test_multiple_join_nodes nipype/pipeline/engine/tests/test_join.py::test_identity_join_node nipype/pipeline/engine/tests/test_join.py::test_multifield_join_node nipype/pipeline/engine/tests/test_join.py::test_synchronize_join_node nipype/pipeline/engine/tests/test_join.py::test_itersource_join_source_node nipype/pipeline/engine/tests/test_join.py::test_itersource_two_join_nodes nipype/pipeline/engine/tests/test_join.py::test_set_join_node_file_input nipype/pipeline/engine/tests/test_join.py::test_nested_workflow_join
nipype/pipeline/engine/utils.py
nipype/pipeline/engine/utils.py